mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: error for consts in fns
This commit is contained in:
parent
172e4ff853
commit
2e0b9de31c
6
vlib/v/checker/tests/const_define_in_function_err.out
Normal file
6
vlib/v/checker/tests/const_define_in_function_err.out
Normal file
@ -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 | }
|
4
vlib/v/checker/tests/const_define_in_function_err.vv
Normal file
4
vlib/v/checker/tests/const_define_in_function_err.vv
Normal file
@ -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
Block a user