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:
parent
d307ab2c7c
commit
9e61321d4c
@ -528,8 +528,16 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
||||
}
|
||||
}
|
||||
if node.is_noreturn {
|
||||
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();})')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
11
vlib/v/tests/unreachable_code_paths_test.v
Normal file
11
vlib/v/tests/unreachable_code_paths_test.v
Normal file
@ -0,0 +1,11 @@
|
||||
fn test_inside_ternary() {
|
||||
x := if false {
|
||||
'foo'
|
||||
} else if true {
|
||||
'bar'
|
||||
} else {
|
||||
panic('err')
|
||||
'empty'
|
||||
}
|
||||
assert x == 'bar'
|
||||
}
|
Loading…
Reference in New Issue
Block a user