Open frmdstryr opened 3 years ago
I think the problem is it's treating each pipe as a bitwise or which is fine until it sees a {
.
This is not really specific to optionals, even a missing paren in a comparision leads to strange error messages eg https://zig.godbolt.org/z/Wj341P
const std = @import("std");
pub fn main() !void {
if ( value > 1 {
std.log.warn("{}", .{value});
}
}
leads to this
<source>:5:37: error: expected token '}', found ';'
std.log.warn("{}", .{value});
^
ASM generation compiler returned: 1
<source>:5:37: error: expected token '}', found ';'
std.log.warn("{}", .{value});
^
Execution build compiler returned: 1
So it seems like the parser is accepting blocks in places that don't make sense.
Unless there's a block label I don't think it should allow the opening {
.
I've hit this too many times by accident now... so another minor nitpick/potential error message improvement... or possibly a parser issue.
If you forget to add a closing paren
)
in an optional if the error always points to the end of the if block however it should know right at the first|
that a paren is missing.https://zig.godbolt.org/z/Eb71E5
After scanning through the stage2 parser a little it seems like the error is at the end because the
Expr
seems to be capturing the Payload so any valid expression before the closing paren puts the error at the bottom while.Edit this might be a parser bug... as https://zig.godbolt.org/z/fh99P1 gives the same error