ziglang / zig-spec

MIT License
170 stars 32 forks source link

Grammar allows for operations preceding break/continue keywords #55

Open connorjclark opened 2 months ago

connorjclark commented 2 months ago
while (true) {
    !break;
}

while (true) {
    --break;
}

while (true) {
    1 + break;
}

All three pass the grammar as defined in grammar.y, and I believe the first two have no impact on actual zig compilation results. The third one fails the zig compiler due to unreachable code (it considers the 1 + to be unreachable)

PrimaryExpr is the relevant rule. All of the binary and unary operations coming in from PrefixExpr on the left-hand-side is what allows for this unexpected grammar.