A comptime-constructed type with NO members is now VALID for every kind
(empty struct, empty tuple, empty enum, empty tagged_union) — only a bare
`declare("X")` placeholder that is never completed by a matching `define`
stays rejected (it would panic codegen).
- comptime_vm.zig registerTypeVm: drop the blanket "a type with no members
is never valid" rejection. The per-kind loops are vacuous for an empty
member list and the dup-name checks stay correct.
- types.zig TaggedUnionInfo: add `defined: bool = true`. Every real
construction (normal unions, error sets, register_type completion) is
"defined" by default; only the two declare-PLACEHOLDER sites set it false:
comptime_vm.declareNominal and lower/comptime.preregisterForwardTypes.
- lower/comptime.checkComptimeTypeResult: reject on `!defined` (never-defined
placeholder) instead of `fields.len == 0`, so an explicitly-defined empty
union passes through while a never-completed declare is still gated.
- types.zig typeSizeBytes(tagged_union): floor the payload area at 8 bytes
when no field carries a payload, mirroring the LLVM lowering — fixes a
verifySizes panic on an empty/all-void tagged_union (IR sized to tag-only,
LLVM laid out tag + [8 x i8]).
Tests:
- examples/1179: repurposed from "empty enum rejected" (now valid) to the
never-defined `declare` case (the remaining rejection); preserves its
issue-0140 regression role.
- examples/1180 (duplicate variant): still rejected, unchanged output.
- examples/0641 (new): construct empty struct/tuple/enum/tagged_union via
define/declare; instantiate the constructible ones; exit 0.
31 lines
1.3 KiB
Plaintext
31 lines
1.3 KiB
Plaintext
// A comptime type construction (declare/define, reflection) that leaves a type
|
|
// INCOMPLETE 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 `declare("Undefined")` mints a
|
|
// forward nominal slot that is NEVER completed by a matching `define(handle, …)`;
|
|
// the compiler rejects the incomplete type at its construction site (exit 1, no
|
|
// panic).
|
|
//
|
|
// NOTE: an EXPLICITLY-defined empty type (empty struct/tuple/enum/tagged_union)
|
|
// is VALID — see examples/0641. The remaining rejection is purely the
|
|
// never-defined `declare` placeholder, which would otherwise panic codegen
|
|
// (`verifySizes`: llvm_size != ir_size on an unsized forward slot).
|
|
//
|
|
// 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";
|
|
|
|
// Declared but never `define`d — an incomplete forward slot.
|
|
mk_undefined :: () -> Type {
|
|
return declare("Undefined");
|
|
}
|
|
|
|
Undefined :: mk_undefined();
|
|
|
|
main :: () -> i32 {
|
|
u : Undefined = ---;
|
|
return 0;
|
|
}
|