parent
27f5c35bde
commit
4d0f835548
|
@ -1586,8 +1586,13 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
}
|
||||
// []T << T or []T << []T
|
||||
unwrapped_right_type := c.unwrap_generic(right_type)
|
||||
if c.check_types(unwrapped_right_type, left_value_type)
|
||||
|| c.check_types(unwrapped_right_type, c.unwrap_generic(left_type)) {
|
||||
if c.check_types(unwrapped_right_type, left_value_type) {
|
||||
// []&T << T is wrong: we check for that, !(T.is_ptr()) && ?(&T).is_ptr()
|
||||
if !(!unwrapped_right_type.is_ptr() && left_value_type.is_ptr()
|
||||
&& left_value_type.share() == .mut_t) {
|
||||
return ast.void_type
|
||||
}
|
||||
} else if c.check_types(unwrapped_right_type, c.unwrap_generic(left_type)) {
|
||||
return ast.void_type
|
||||
}
|
||||
c.error('cannot append `$right_sym.name` to `$left_sym.name`', right_pos)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/invalid_insert_references_test.vv:8:7: error: cannot append `int literal` to `[]&int`
|
||||
6 | a << &c
|
||||
7 | c = 2
|
||||
8 | a << 1
|
||||
| ^
|
||||
9 | println(a)
|
||||
10 | }
|
|
@ -0,0 +1,14 @@
|
|||
// fixes https://github.com/vlang/v/issues/3600, test based on a simplified version of example by https://github.com/radare
|
||||
fn test_invalid_insert_references() {
|
||||
b := 0
|
||||
mut a := [&b]
|
||||
mut c := 1
|
||||
a << &c
|
||||
c = 2
|
||||
a << 1
|
||||
println(a)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_invalid_insert_references()
|
||||
}
|
Loading…
Reference in New Issue