1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix VUNREACHABLE inside ternary (#10672)

This commit is contained in:
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 { if node.is_noreturn {
if g.inside_ternary == 0 {
g.writeln(';') g.writeln(';')
g.write('VUNREACHABLE()') 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'
}