Re:Easy Interfaces with Zig 0.10.0
by frou_dh on Thursday November 17, 2022 @06:05AM
(#33637327)
Something I found eyebrow-raising is that the type of the expression expected in the parenthesised part of an `if () { ... }` actually changes based on what syntax is used on an `else` line that comes later.
[ Parent
| on HN ]
I haven't seen that yet. Could you give an example?
IIRC in the following, the expected type of `x` in B stops being bool (but I no longer have a Zig env set up so I can't test it).
# A
if (x) {
...
} else {
...
}
# B
if (x) {
...
} else |y| {
...
}That looks right. If/else is overloaded as doing the normal thing with bools by default, and if you try to capture something exceptional with `else |y|` then the type of `x` is inferred to be something capable of such a capture -- optionals or error unions.