From 4da6add3347ee9fb650c72e95a4600a249cdbeea Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 17 Jun 2026 04:36:09 +0300 Subject: [PATCH] test(0140): pin comptime type-construction bail diagnostic (examples/1179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the issue 0140 repro into the feature suite as a regression test. Asserts the build-gating diagnostic 'comptime type construction failed: comptime define(): enum has no variants' at the construction site, exit 1 — locking out the prior 'unresolved type reached LLVM emission' panic. --- ...nostics-comptime-type-construction-bail.sx | 19 ++++++++++++++++++ ...stics-comptime-type-construction-bail.exit | 1 + ...ics-comptime-type-construction-bail.stderr | 5 +++++ ...ics-comptime-type-construction-bail.stdout | 1 + ...type-construction-bail-unresolved-panic.sx | 20 ------------------- 5 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 examples/1179-diagnostics-comptime-type-construction-bail.sx create mode 100644 examples/expected/1179-diagnostics-comptime-type-construction-bail.exit create mode 100644 examples/expected/1179-diagnostics-comptime-type-construction-bail.stderr create mode 100644 examples/expected/1179-diagnostics-comptime-type-construction-bail.stdout delete mode 100644 issues/0140-comptime-type-construction-bail-unresolved-panic.sx diff --git a/examples/1179-diagnostics-comptime-type-construction-bail.sx b/examples/1179-diagnostics-comptime-type-construction-bail.sx new file mode 100644 index 00000000..09a2e05e --- /dev/null +++ b/examples/1179-diagnostics-comptime-type-construction-bail.sx @@ -0,0 +1,19 @@ +// A comptime type construction (declare/define, reflection) that bails in the +// interpreter must surface a build-gating DIAGNOSTIC naming the reason — not +// poison the decl to `.unresolved` silently and let that crash at LLVM emission +// or hide behind a downstream cascade. Here `define` is handed an empty variant +// list; the interp bails "enum has no variants", and `evalComptimeType` renders +// that at the construction site (exit 1, no panic). +// +// Regression (issue 0140): before the fix this panicked with "unresolved type +// reached LLVM emission" (exit 134), because the interp's bail detail was +// dropped (`catch return null`) and `.unresolved` reached codegen unannounced. +#import "modules/std.sx"; +#import "modules/std/meta.sx"; + +Empty :: define(declare("Empty"), .enum(.{ variants = .[] })); + +main :: () -> i32 { + e : Empty = ---; + return 0; +} diff --git a/examples/expected/1179-diagnostics-comptime-type-construction-bail.exit b/examples/expected/1179-diagnostics-comptime-type-construction-bail.exit new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/examples/expected/1179-diagnostics-comptime-type-construction-bail.exit @@ -0,0 +1 @@ +1 diff --git a/examples/expected/1179-diagnostics-comptime-type-construction-bail.stderr b/examples/expected/1179-diagnostics-comptime-type-construction-bail.stderr new file mode 100644 index 00000000..9bcffd6f --- /dev/null +++ b/examples/expected/1179-diagnostics-comptime-type-construction-bail.stderr @@ -0,0 +1,5 @@ +error: comptime type construction failed: comptime define(): enum has no variants + --> examples/1179-diagnostics-comptime-type-construction-bail.sx:14:10 + | +14 | Empty :: define(declare("Empty"), .enum(.{ variants = .[] })); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/examples/expected/1179-diagnostics-comptime-type-construction-bail.stdout b/examples/expected/1179-diagnostics-comptime-type-construction-bail.stdout new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/expected/1179-diagnostics-comptime-type-construction-bail.stdout @@ -0,0 +1 @@ + diff --git a/issues/0140-comptime-type-construction-bail-unresolved-panic.sx b/issues/0140-comptime-type-construction-bail-unresolved-panic.sx deleted file mode 100644 index 4a9d365d..00000000 --- a/issues/0140-comptime-type-construction-bail-unresolved-panic.sx +++ /dev/null @@ -1,20 +0,0 @@ -// Repro for issue 0140 — a FAILING comptime type construction -// (`define` with an empty variant list) bails correctly in the interp -// ("comptime define(): enum has no variants"), but that bail is swallowed: -// `evalComptimeType` returns null, the decl is poisoned to `.unresolved` -// with NO diagnostic, and the `.unresolved` type reaches LLVM emission and -// PANICS ("unresolved type reached LLVM emission") instead of surfacing a -// clean error with the bail reason. -// -// Expected: a build-time diagnostic at the construction site naming the -// bail reason (e.g. "comptime type construction failed: enum has no -// variants"), exit 1, no panic. -#import "modules/std.sx"; -#import "modules/std/meta.sx"; - -Empty :: define(declare("Empty"), .enum(.{ variants = .[] })); - -main :: () -> i32 { - e : Empty = ---; - return 0; -}