parser: error for consts in fns
parent
172e4ff853
commit
2e0b9de31c
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/const_define_in_function_err.v:2:2: error: const can only be defined at the top level (outside of functions)
|
||||
1 | fn main() {
|
||||
2 | const (a = 1)
|
||||
| ~~~~~
|
||||
3 | println(a)
|
||||
4 | }
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
const (a = 1)
|
||||
println(a)
|
||||
}
|
|
@ -504,6 +504,9 @@ pub fn (mut p Parser) stmt() ast.Stmt {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if p.tok.kind == .key_const {
|
||||
p.error_with_pos('const can only be defined at the top level (outside of functions)', p.tok.position())
|
||||
}
|
||||
epos := p.tok.position()
|
||||
return ast.ExprStmt{
|
||||
expr: p.expr(0)
|
||||
|
|
Loading…
Reference in New Issue