You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser accepts a closure return annotation (x: i32) -> str => x and silently drops it #1508
Parser.parse_fat_arrow_paren_closure and Parser.parse_closure (src/Parser.w) parse an optional -> TYPE after a closure's parameter list with self.parse_type_expr() and discard the result. The type node is never stored on the NK_CLOSURE node, so Sema never sees it:
fn main:
let f = (x: i32) -> str => x
let y: i32 = f(2)
print(f"{y}")
Actual (stage1 of origin/main f1e3bd2 + the #1402 closure-parameter fix): compiles, runs, and prints 2. The written return type str has no effect.
This is the forbidden silent case: the compiler accepts a construct and behaves as if it were not written (CLAUDE.md, No Silent Fallbacks).
What the spec says: §9.3 shows closures only as x => x + 1, (x, y) => x * y, () => ..., and it says "The -> token is reserved exclusively for return type annotations (e.g., fn foo() -> i32)". The spec does not say whether a closure may declare its return type, so which fix is right is a ruling:
(a) the annotation is part of the closure's type: the body is checked against it and the closure's fn type returns it; or
(b) the form is not part of the language, and -> after a closure's parameter list is a parse error that names the fix.
Either way, it must not be parsed and then dropped.
Found while fixing #1402 (closure parameter annotations with generic types), which sits in the same two parser functions.
Decision (from canon, no ruling needed): the spec's closure sections (§12.1–12.4) define no closure return annotation, and parsing -> TYPE then dropping it is a No Silent Fallbacks violation. A closure return annotation is a parse error with the fix-it: "closures infer their return type; annotate the binding or the expected function type instead". Implement in the next frontend batch.
Activity
Closure parameter annotations keep a generic type whole: (v: &Vec[i32…
ehartford commentedon Sep 23, 2026
Decision (from canon, no ruling needed): the spec's closure sections (§12.1–12.4) define no closure return annotation, and parsing
-> TYPEthen dropping it is a No Silent Fallbacks violation. A closure return annotation is a parse error with the fix-it: "closures infer their return type; annotate the binding or the expected function type instead". Implement in the next frontend batch.Closure parameter annotations keep a generic type whole: (v: &Vec[i32…
D71 language rulings: @[flags] without repr, from_int on unit enums, …