checker: check __global type (#9804)
parent
8e455495b2
commit
aa40dfc1de
|
@ -519,6 +519,7 @@ pub:
|
||||||
expr Expr
|
expr Expr
|
||||||
has_expr bool
|
has_expr bool
|
||||||
pos token.Position
|
pos token.Position
|
||||||
|
typ_pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
typ Type
|
typ Type
|
||||||
comments []Comment
|
comments []Comment
|
||||||
|
|
|
@ -3834,6 +3834,10 @@ fn (mut c Checker) global_decl(node ast.GlobalDecl) {
|
||||||
if field.name in c.global_names {
|
if field.name in c.global_names {
|
||||||
c.error('duplicate global `$field.name`', field.pos)
|
c.error('duplicate global `$field.name`', field.pos)
|
||||||
}
|
}
|
||||||
|
sym := c.table.get_type_symbol(field.typ)
|
||||||
|
if sym.kind == .placeholder {
|
||||||
|
c.error('unknown type `$sym.name`', field.typ_pos)
|
||||||
|
}
|
||||||
c.global_names << field.name
|
c.global_names << field.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
vlib/v/checker/tests/globals/unknown_typ.vv:1:12: error: unknown type `foo`
|
||||||
|
1 | __global x foo
|
||||||
|
| ~~~
|
||||||
|
2 | __global (
|
||||||
|
3 | y = float(5.0)
|
||||||
|
vlib/v/checker/tests/globals/unknown_typ.vv:3:6: error: unknown type `float`
|
||||||
|
1 | __global x foo
|
||||||
|
2 | __global (
|
||||||
|
3 | y = float(5.0)
|
||||||
|
| ~~~~~
|
||||||
|
4 | )
|
|
@ -0,0 +1,4 @@
|
||||||
|
__global x foo
|
||||||
|
__global (
|
||||||
|
y = float(5.0)
|
||||||
|
)
|
|
@ -2846,6 +2846,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl {
|
||||||
if has_expr {
|
if has_expr {
|
||||||
p.next() // =
|
p.next() // =
|
||||||
}
|
}
|
||||||
|
typ_pos := p.tok.position()
|
||||||
typ := p.parse_type()
|
typ := p.parse_type()
|
||||||
if p.tok.kind == .assign {
|
if p.tok.kind == .assign {
|
||||||
p.error('global assign must have the type around the value, use `name = type(value)`')
|
p.error('global assign must have the type around the value, use `name = type(value)`')
|
||||||
|
@ -2866,6 +2867,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl {
|
||||||
has_expr: has_expr
|
has_expr: has_expr
|
||||||
expr: expr
|
expr: expr
|
||||||
pos: pos
|
pos: pos
|
||||||
|
typ_pos: typ_pos
|
||||||
typ: typ
|
typ: typ
|
||||||
comments: comments
|
comments: comments
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue