parser: fix if-guard redefinition (#9425)
parent
1b572f75e8
commit
3753a58ce0
|
@ -87,6 +87,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
|||
is_guard = true
|
||||
var_pos := p.tok.position()
|
||||
var_name := p.check_name()
|
||||
if p.scope.known_var(var_name) {
|
||||
p.error_with_pos('redefinition of `$var_name`', var_pos)
|
||||
}
|
||||
comments << p.eat_comments({})
|
||||
p.check(.decl_assign)
|
||||
comments << p.eat_comments({})
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/parser/tests/if_guard_redefinition.vv:7:8: error: redefinition of `x`
|
||||
5 | fn main() {
|
||||
6 | x := 1
|
||||
7 | if x := opt_fn() {
|
||||
| ^
|
||||
8 | println(x)
|
||||
9 | }
|
|
@ -0,0 +1,10 @@
|
|||
fn opt_fn() ?int {
|
||||
return 2
|
||||
}
|
||||
|
||||
fn main() {
|
||||
x := 1
|
||||
if x := opt_fn() {
|
||||
println(x)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue