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
Originally posted by programandala-net April 12, 2026
i have found out a curious issue about nested if expressions; i have isolated it in this example code:
importrandfnchance() bool {
return rand.i8() >=0
}
fnmain() {
// these nested `if` expressions are compiled fine// (note a literal is added to the *outer* `if` expression):_:=ifchance() { 0 } else { ifchance() { 2 } else { 3 } } +5_:=ifchance() { 'a' } else { ifchance() { 'c' } else { 'd' } } +'f'// but when something is added to the *inner* `if` expression, the compilation// fails:// XXX compilation error: mismatched types `void` and `int literal`:// _ := if chance() { 0 } else { if chance() { 2 } else { 3 } + 4 } + 5// XXX compilation error: mismatched types `void` and `string`:// _ := if chance() { 'a' } else { if chance() { 'c' } else { 'd' } + 'e'} + 'f'// and when the inner `if` expression is added to something, the// compilation works:_:=ifchance() { 0 } else { 1+ifchance() { 2 } else { 3 } +4 } +5_:=ifchance() { 'a' } else { 'b'+ifchance() { 'c' } else { 'd' } +'e'} +'f'
}
i have searched the documentation, the github issues and the github discussions but found nothing related.
it seems a bug, but perhaps i am neglecting something, so i prefer to ask here first, before opening an issue.
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.
Discussed in #26864
Originally posted by programandala-net April 12, 2026
i have found out a curious issue about nested
ifexpressions; i have isolated it in this example code:i have searched the documentation, the github issues and the github discussions but found nothing related.
it seems a bug, but perhaps i am neglecting something, so i prefer to ask here first, before opening an issue.
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.