A failable function that returned by IMPLICIT success (no explicit
`return`) left its error-tag slot uninitialized, so a caller's `catch` /
`or` (or `main`) read a garbage tag and reported a phantom unhandled
error — and for value-carrying failables the success value was dropped.
The "no error" sentinel was only written on the explicit-`return;` path.
Unified all function-body-return lowering so the failable-success slot
is always written:
- void `-> !` fall-through: `ensureTerminator` (control_flow.zig) now
emits `ret constInt(0)` for a pure-failable end-of-body.
- value-failable trailing-expression success: `lowerValueBody`
(stmt.zig) routes through `lowerFailableSuccessReturn`.
- generic + pack-fn instances: `monomorphizeFunction` (generic.zig) and
`monomorphizePackFn` (pack.zig) now DELEGATE their body-return to
`lowerValueBody` instead of hand-rolling a `coerce`+`ret` that drifted
(covers generic/pack value-failables).
Also fixes the missing-value diagnostic guard added here: it now counts
`.err`-level diagnostics (new `DiagnosticList.errorCount`) rather than the
total list length, so a warning/note emitted while lowering the body
(e.g. an ObjC selector arity warning) can no longer suppress a genuine
"body produces no value" error — which previously shipped an
uninitialized return at exit 0.
Regressions: examples/errors/1061 (void fall-through), 1062 (value-failable
trailing expr), 1063 (generic value-failable trailing expr).
22 lines
862 B
Plaintext
22 lines
862 B
Plaintext
// A pure-failable function (`-> !`) that succeeds by IMPLICIT fall-through —
|
|
// no explicit `return;` — must initialize its error-channel slot to 0 ("no
|
|
// error"), exactly like an explicit `return;` would. Otherwise the slot is
|
|
// left undefined and a caller's `catch` (or `main`) reads a garbage tag and
|
|
// reports a phantom unhandled error.
|
|
//
|
|
// This exercises:
|
|
// - a `-> !` callee that falls off the end (no `return;`) — its `catch`
|
|
// handler must NOT fire;
|
|
// - a `main :: () -> !` that falls off the end — must exit 0.
|
|
//
|
|
// Regression (issue 0190).
|
|
|
|
#import "modules/std.sx";
|
|
|
|
noop :: () -> ! { } // success by fall-through, no `return;`
|
|
|
|
main :: () -> ! {
|
|
noop() catch (e) { print("phantom: {}\n", e); }; // must NOT fire
|
|
print("ok\n"); // main falls through → exit 0
|
|
}
|