ziglang / zig-spec

MIT License
170 stars 32 forks source link

What is LoopTypeExpr supposed to match? #53

Closed McSinyx closed 7 months ago

McSinyx commented 7 months ago

In grammar.y, as part of PrimaryTypeExpr:

LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)

ForTypeExpr <- ForPrefix TypeExpr (KEYWORD_else TypeExpr)?

WhileTypeExpr <- WhilePrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?

This confuses me, since it would match something like while (true) u8. What do I miss?

Vexu commented 7 months ago

Loops, like any other expressions, can also be used in type expressions:

fn foo(comptime T: type) for (.{u32, f32, bool}) |I| (if (I == T) break I) else void {
    // IDK why you'd do something like this...
}
McSinyx commented 7 months ago

(if (I == T) break I)

Woah thanks, I missed that TypeExpr can just be an Expr in a trench coat of parentheses :sweat_smile: