checker: improve array literal element type mismatch error (#6825)
parent
cd2a2cef25
commit
4882d338f0
|
@ -2300,10 +2300,8 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
|
|||
c.expected_type = elem_type
|
||||
continue
|
||||
}
|
||||
if !c.check_types(typ, elem_type) {
|
||||
elem_type_sym := c.table.get_type_symbol(elem_type)
|
||||
c.error('expected array element with type `$elem_type_sym.source_name`',
|
||||
array_init.pos)
|
||||
c.check_expected(typ, elem_type) or {
|
||||
c.error('invalid array element: $err', expr.position())
|
||||
}
|
||||
}
|
||||
if expecting_interface_array {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
vlib/v/checker/tests/array_element_type.vv:2:8: error: unknown type `abc`
|
||||
1 | fn main() {
|
||||
2 | _ = []abc{}
|
||||
| ~~~
|
||||
3 | _ = [2, '']
|
||||
4 | }
|
||||
vlib/v/checker/tests/array_element_type.vv:3:10: error: invalid array element: expected `int`, not `string`
|
||||
1 | fn main() {
|
||||
2 | _ = []abc{}
|
||||
3 | _ = [2, '']
|
||||
| ~~
|
||||
4 | }
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
_ = []abc{}
|
||||
_ = [2, '']
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
vlib/v/checker/tests/unknown_array_element_type_a.vv:2:9: error: unknown type `abc`
|
||||
1 | fn main() {
|
||||
2 | a := []abc{}
|
||||
| ~~~
|
||||
3 | println(a)
|
||||
4 | }
|
|
@ -1,4 +0,0 @@
|
|||
fn main() {
|
||||
a := []abc{}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue