Files
sx/issues/0060-closure-literal-composition-miscompiles.sx
agra 485b4fa618 issues: file 0060 — closure-literal composition miscompiles (blocks ERR/E5.1)
Probing ERR/E5.1 (composition with closures) surfaced pre-existing closure-
literal lowering bugs: a closure literal passed as a function-type argument and
called inside the callee returns wrong values (block-body 192, arrow-body 20,
want 10 — non-failable too; the working contrast passes the value as a separate
arg, examples/0302). On top of that, failable closure returns don't parse
(isLambda omits .bang — one-line fix in the issue) and arrow-body failable
closures miscompile (return 0); block-body failable closures called directly
work. Runnable repro + parser patch + investigation prompt in the issue.

E5.1 paused per the impassable rule rather than built on miscompiling closures;
the parser fix + a regression example were reverted to avoid landing silently-
miscompiling failable closures on master.
2026-06-01 20:18:25 +03:00

16 lines
631 B
Plaintext

// Repro for issue 0060: a closure LITERAL passed directly as a function-type
// argument, where the callee calls it with a literal, miscompiles. The working
// contrast is examples/0302-closures-closures.sx, where the value flows in as a
// SEPARATE argument (`apply(f, x) { return f(x); }`).
//
// Expected: block=10, arrow=10. Actual: block=192, arrow=20.
#import "modules/std.sx";
apply :: (f: (s64) -> s64) -> s64 { return f(5); }
main :: () {
print("block={}\n", apply(closure((x: s64) -> s64 { return x * 2; }))); // want 10
print("arrow={}\n", apply(closure((x: s64) -> s64 => x * 2))); // want 10
}