cgen: fix error for anon fn decl inside ternary (#14150)
parent
81963b51ab
commit
b314b8d8bf
|
@ -379,7 +379,10 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
|
|||
defer {
|
||||
g.tmp_count = ctmp
|
||||
}
|
||||
prev_inside_ternary := g.inside_ternary
|
||||
g.inside_ternary = 0
|
||||
g.stmts(node.stmts)
|
||||
g.inside_ternary = prev_inside_ternary
|
||||
if node.is_noreturn {
|
||||
g.writeln('\twhile(1);')
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
fn foofun(op rune) fn () string {
|
||||
return match op {
|
||||
`1` {
|
||||
fn () string {
|
||||
return '1 passed'
|
||||
}
|
||||
}
|
||||
`2` {
|
||||
fn () string {
|
||||
return '2 passed'
|
||||
}
|
||||
}
|
||||
else {
|
||||
fn () string {
|
||||
return 'Nor 1 or 2 passed'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_anon_fn_decl_inside_ternary() {
|
||||
a := foofun(`1`)
|
||||
println(a())
|
||||
assert a() == '1 passed'
|
||||
}
|
Loading…
Reference in New Issue