checker: add error for struct fields of type []unknown
parent
60716bba29
commit
28ffe2a6ee
|
@ -264,6 +264,13 @@ pub fn (mut c Checker) struct_decl(decl ast.StructDecl) {
|
|||
if sym.kind == .placeholder && decl.language != .c && !sym.name.starts_with('C.') {
|
||||
c.error('unknown type `$sym.name`', field.pos)
|
||||
}
|
||||
if sym.kind == .array {
|
||||
array_info := sym.array_info()
|
||||
elem_sym := c.table.get_type_symbol(array_info.elem_type)
|
||||
if elem_sym.kind == .placeholder {
|
||||
c.error('unknown type `$elem_sym.name`', field.pos)
|
||||
}
|
||||
}
|
||||
if sym.kind == .struct_ {
|
||||
info := sym.info as table.Struct
|
||||
if info.is_ref_only && !field.typ.is_ptr() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/unknown_array_element_type.v:2:9: error: unknown type `abc`
|
||||
vlib/v/checker/tests/unknown_array_element_type_a.v:2:9: error: unknown type `abc`
|
||||
1 | fn main() {
|
||||
2 | a := []abc{}
|
||||
| ~~~
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/unknown_array_element_type_b.v:2:2: error: unknown type `abc`
|
||||
1 | struct Aaa {
|
||||
2 | a []abc
|
||||
| ~~~~~~~
|
||||
3 | }
|
||||
4 |
|
|
@ -0,0 +1,9 @@
|
|||
struct Aaa {
|
||||
a []abc
|
||||
}
|
||||
|
||||
fn main() {
|
||||
s := Aaa{}
|
||||
println(s)
|
||||
}
|
||||
|
|
@ -105,9 +105,9 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
|||
}
|
||||
field_start_pos := p.tok.position()
|
||||
field_name := p.check_name()
|
||||
field_pos := field_start_pos.extend(p.tok.position())
|
||||
// p.warn('field $field_name')
|
||||
typ := p.parse_type()
|
||||
field_pos := field_start_pos.extend(p.tok.position())
|
||||
/*
|
||||
if name == '_net_module_s' {
|
||||
s := p.table.get_type_symbol(typ)
|
||||
|
|
Loading…
Reference in New Issue