(?T) orelse (?T)
yields different result type with comptime
-known arguments
#16793
Labels
question
No questions on the issue tracker, please.
Zig Version
0.11.0-dev.4056+996eb0174
Steps to Reproduce and Observed Behavior
Reproducing example:
The second line fails with the following compile error:
It seems that (x orelse y) can result in a non-optional type if some operands are
comptime
-known.Strangely enough, grouping the
orelse
to be right-associative (argument orelse (argument orelse 20)
) fixes the issue in this case (see also #15108).I think that's even a universal workaround - but maybe there's some edge case I'm not considering.
Expected Behavior
I'd expect
(?T) orelse (?T)
to always result in(?T)
, both withcomptime
-known arguments and without.However now that I have typed all this out, it does remind me of #16595 , where it was deemed correct behavior to not analyze the RHS, leading to a different deduced result type.
The main difference I see is that there it was about fully knowing the type, whereas here it's about fully knowing the value (or at least, that the value isn't
null
).But you decide whether it's a bug or WAI (working as intended).
The text was updated successfully, but these errors were encountered: