You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
V version:V 0.5.2 (master) OS: Linux (reported via bugs.vlang.io)
Description
A match whose arms use ! error-propagation (f(value)!), when the match is used as the value of an if-expression (here an if value := opt { … } else { … } option-guard assigned to a variable), emits invalid C: the result temp is assigned an empty expression — _t4 = ; — giving expected expression. Replacing the !-propagating arms with plain expressions compiles fine, so the trigger is !-propagation inside a match-as-if-expr-value.
Reproduction
modulemainstructFirst {}
structSecond {}
typeNode= First | Second
fnlower_first(_ First) !int {
return1
}
fnlower_second(_ Second) !int {
return2
}
fnselect_value(node ?Node) !int {
result:=ifvalue:= node {
match value {
First { lower_first(value)! }
Second { lower_second(value)! }
}
} else {
0
}
return result
}
fnmain() {
println(select_value(First{})!)
}
Actual (generated C fails to compile)
error: expected expression
_t4 = ;
The result temp for the if/match expression is never assigned the propagated value.
Expected
Compiles; the match arms' !-propagated results are assigned to the if-expression's result temp.
Note
The identical code with non-! arms (First { 1 } Second { 2 }, and a non-! return type) compiles and runs correctly.
Reported via bugs.vlang.io
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
V version:
V 0.5.2(master)OS: Linux (reported via bugs.vlang.io)
Description
A
matchwhose arms use!error-propagation (f(value)!), when thematchis used as the value of anif-expression (here anif value := opt { … } else { … }option-guard assigned to a variable), emits invalid C: the result temp is assigned an empty expression —_t4 = ;— givingexpected expression. Replacing the!-propagating arms with plain expressions compiles fine, so the trigger is!-propagation inside a match-as-if-expr-value.Reproduction
Actual (generated C fails to compile)
The result temp for the
if/matchexpression is never assigned the propagated value.Expected
Compiles; the
matcharms'!-propagated results are assigned to the if-expression's result temp.Note
The identical code with non-
!arms (First { 1 } Second { 2 }, and a non-!return type) compiles and runs correctly.Reported via bugs.vlang.io
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.