cgen: fix VUNREACHABLE inside ternary (#10672)

pull/10677/head weekly.2021.27
Lukas Neubert 2021-07-05 17:26:01 +02:00 committed by GitHub
parent d307ab2c7c
commit 9e61321d4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -528,8 +528,16 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
}
}
if node.is_noreturn {
g.writeln(';')
g.write('VUNREACHABLE()')
if g.inside_ternary == 0 {
g.writeln(';')
g.write('VUNREACHABLE()')
} else {
$if msvc {
// MSVC has no support for the statement expressions used below
} $else {
g.write(', ({VUNREACHABLE();})')
}
}
}
}

View File

@ -0,0 +1,11 @@
fn test_inside_ternary() {
x := if false {
'foo'
} else if true {
'bar'
} else {
panic('err')
'empty'
}
assert x == 'bar'
}