fix(0140): surface comptime type-construction bail as a diagnostic
evalComptimeType did `interp.call(...) catch return null`, dropping the
interp's last_bail_detail; callers poisoned to .unresolved with no
diagnostic, so the sentinel reached LLVM emission and panicked
("unresolved type reached LLVM emission"), or hid behind a downstream
cascade.
Clear last_bail_detail before the call; on the catch emit a build-gating
.err at the construction expr's span ("comptime type construction
failed: {detail}", mirroring the #run surfacing in emit_llvm.zig), then
return null to keep the .unresolved poison — now gated by a real message
so no unresolved type reaches emission unannounced.
Empty-variant define now prints 'comptime define(): enum has no
variants' and exits 1 (no panic); make_enum-style computed-slice
failures show their root reason at the construction site.
This commit is contained in:
@@ -454,7 +454,25 @@ pub fn evalComptimeType(self: *Lowering, expr: *const Node) ?TypeId {
|
||||
if (self.diagnostics) |d| if (d.import_sources) |sm| interp.setSourceMap(sm);
|
||||
interp.setMintTable(&self.module.types);
|
||||
|
||||
const result = interp.call(func_id, &.{}) catch return null;
|
||||
// Clear the interp's last-bail channel so a bail HERE is attributable to
|
||||
// THIS construction (not a stale message from an earlier comptime eval).
|
||||
interp_mod.Interpreter.last_bail_detail = null;
|
||||
const result = interp.call(func_id, &.{}) catch |err| {
|
||||
// A comptime type construction (declare/define, reflection) that bails
|
||||
// must surface a build-gating diagnostic naming the reason — NOT poison
|
||||
// to `.unresolved` silently and let that crash at LLVM emission
|
||||
// ("unresolved type reached LLVM emission") or hide behind a downstream
|
||||
// cascade (issue 0140). The interp's `bailDetail` already set the precise
|
||||
// reason; mirror the `#run` path (emit_llvm.zig) and render it. Returning
|
||||
// null keeps the `.unresolved` poison for the caller, but now the build
|
||||
// is gated by a real message, so no unresolved type reaches emission
|
||||
// unannounced.
|
||||
if (self.diagnostics) |d| {
|
||||
const detail = interp_mod.Interpreter.last_bail_detail orelse @errorName(err);
|
||||
d.addFmt(.err, expr.span, "comptime type construction failed: {s}", .{detail});
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return result.asTypeId();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user