1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add error for struct fields of type []unknown

This commit is contained in:
yuyi 2020-05-29 00:38:53 +08:00 committed by GitHub
parent 60716bba29
commit 28ffe2a6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 2 deletions

View File

@ -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.') { if sym.kind == .placeholder && decl.language != .c && !sym.name.starts_with('C.') {
c.error('unknown type `$sym.name`', field.pos) 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_ { if sym.kind == .struct_ {
info := sym.info as table.Struct info := sym.info as table.Struct
if info.is_ref_only && !field.typ.is_ptr() { if info.is_ref_only && !field.typ.is_ptr() {

View File

@ -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() { 1 | fn main() {
2 | a := []abc{} 2 | a := []abc{}
| ~~~ | ~~~

View File

@ -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 |

View File

@ -0,0 +1,9 @@
struct Aaa {
a []abc
}
fn main() {
s := Aaa{}
println(s)
}

View File

@ -105,9 +105,9 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
} }
field_start_pos := p.tok.position() field_start_pos := p.tok.position()
field_name := p.check_name() field_name := p.check_name()
field_pos := field_start_pos.extend(p.tok.position())
// p.warn('field $field_name') // p.warn('field $field_name')
typ := p.parse_type() typ := p.parse_type()
field_pos := field_start_pos.extend(p.tok.position())
/* /*
if name == '_net_module_s' { if name == '_net_module_s' {
s := p.table.get_type_symbol(typ) s := p.table.get_type_symbol(typ)