Fix #1021 - Optional `or` branch doesn't define `err`
parent
8a2d25247f
commit
af19aa5096
|
@ -1142,6 +1142,13 @@ fn (p mut Parser) var_decl() {
|
||||||
p.next()
|
p.next()
|
||||||
p.check(LCBR)
|
p.check(LCBR)
|
||||||
p.genln('if (!$tmp .ok) {')
|
p.genln('if (!$tmp .ok) {')
|
||||||
|
p.register_var(Var {
|
||||||
|
name: 'err'
|
||||||
|
typ: 'string'
|
||||||
|
is_mut: false
|
||||||
|
is_used: true
|
||||||
|
})
|
||||||
|
p.genln('string err = $tmp . error;')
|
||||||
p.statements()
|
p.statements()
|
||||||
p.genln('$typ $name = *($typ*) $tmp . data;')
|
p.genln('$typ $name = *($typ*) $tmp . data;')
|
||||||
if !p.returns && p.prev_tok2 != CONTINUE && p.prev_tok2 != BREAK {
|
if !p.returns && p.prev_tok2 != CONTINUE && p.prev_tok2 != BREAK {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn opt_err() ?string {return error('hi')}
|
||||||
|
|
||||||
|
fn test_err(){
|
||||||
|
v := opt_err() or {
|
||||||
|
assert err == 'hi'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert false
|
||||||
|
println(v) // suppress not used error
|
||||||
|
}
|
Loading…
Reference in New Issue