lazyLowerFunction's three exit paths (non-null branch, already-promoted
early return, null-FuncId `ns.fn` qualified-alias branch) each duplicated
the caller-state restore, and the null branch's copy had drifted: it
restored every saved field EXCEPT `block_terminated`. A qualified alias
whose body terminates (e.g. a constant-folded `if true { return ... }`)
leaves `block_terminated = true` after lowerFunction; the null path
returned without resetting it, so the flag leaked into the CALLER's body
lowering and the caller's own trailing statements / `return` were rejected
as dead-after-terminator ("function ... body produces no value").
Fix: collapse the three restores into a single `defer` registered right
after the state is saved, so every exit path restores the identical full
set and the class cannot diverge again. Fields restored on all paths:
current_source_file (F1), scope, func_defer_base, block_terminated (F2),
force_block_value, builder.func/current_block/inst_counter. The
foreign-class / jni-env / pack-mono / inline-return fields already had
their own defers and are unchanged.
Regression: examples/0721-modules-qualified-terminating-callee.sx — a
qualified alias `m.foo` folds `if true { return helper(); }` (helper from
m.sx's own import) and is followed by caller statements + the caller's own
`return 0`. Reports "body produces no value" pre-fix; prints
"terminating-callee: ok" / "after" and exits 0 after. 0719 (collision) and
0720 (F1 own-import visibility) stay green. issues/0100 RESOLVED banner
extended with the F2 follow-up.
32 lines
1.5 KiB
Plaintext
32 lines
1.5 KiB
Plaintext
// Regression (issue 0100 F2): lowering a QUALIFIED imported function whose
|
|
// body terminates must leave the CALLER's lowering state untouched.
|
|
//
|
|
// `m :: #import …` registers `m.foo` as a module-qualified alias with a unique
|
|
// FuncId (the identity fix, issue 0100 / example 0719) and lowers it through
|
|
// `lazyLowerFunction`'s null-FuncId `lowerFunction` path. `foo`'s body folds
|
|
// `if true { return helper(); }` to an unconditional return, so its lowering
|
|
// ends with `block_terminated = true`. The null-FuncId path used to restore
|
|
// every saved caller field EXCEPT `block_terminated`, so that flag leaked back
|
|
// into `main`, and `main`'s own trailing `print` / `return 0` were treated as
|
|
// dead-after-terminator — the compiler rejected `return 0` with "body produces
|
|
// no value". The fix routes all exit paths through one save/restore defer, so
|
|
// the qualified alias is transparent to the caller. (`helper` also lives in
|
|
// m.sx's own flat import, exercising the F1 source-context restore too.)
|
|
|
|
#import "modules/std.sx";
|
|
m :: #import "0721-modules-qualified-terminating-callee/m.sx";
|
|
|
|
report :: (label: string, ok: bool) {
|
|
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
// Qualified callee whose body terminates via a constant-folded `if true`.
|
|
x := m.foo();
|
|
// Caller statements AFTER the call must still be emitted (not dead).
|
|
report("terminating-callee", x == 7);
|
|
print("after\n");
|
|
// The caller's OWN return — rejected pre-fix because block_terminated leaked.
|
|
return 0;
|
|
}
|