fix(0139): reject by-value self-referential types loudly (was a segfault)
A nominal aggregate that contains itself (or a mutual peer) BY VALUE has no
finite layout and infinite-recursed typeSizeBytes into a stack overflow —
for SOURCE enums/structs as well as comptime-constructed types.
New `checkInfiniteSize` pass (lower/decl.zig, Pass 1g — after type
registration, before body lowering): walks the by-VALUE containment graph
(pointer/slice/optional payloads break the cycle, so `*Self` stays valid);
on a back-edge it emits a loud diagnostic — "type 'X' is infinitely sized
(it contains itself by value); use a pointer ('*X') to break the cycle" —
and poisons the offending field to `.unresolved` so sizing can't recurse
before the build halts on the error. Covers source + declare/define types,
direct + mutual recursion.
examples/1178 locks the diagnostic; issue 0139 marked RESOLVED. This also
completes METATYPE PLAN F5's by-value-self-reference rejection. Full suite
green (675).
This commit is contained in:
16
examples/1178-diagnostics-infinite-size-self-reference.sx
Normal file
16
examples/1178-diagnostics-infinite-size-self-reference.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// Diagnostic: a type that contains ITSELF by value has no finite size and must
|
||||
// be rejected loudly (not infinite-loop the size computation into a crash). A
|
||||
// pointer payload (`*Tree`) would break the cycle and is the fix the message
|
||||
// suggests. Covers both source decls and comptime-constructed types — this is
|
||||
// the source form (regression for issue 0139).
|
||||
#import "modules/std.sx";
|
||||
|
||||
Tree :: enum {
|
||||
node: Tree; // by-VALUE self-reference → infinitely sized
|
||||
leaf;
|
||||
}
|
||||
|
||||
main :: () -> i32 {
|
||||
t : Tree = .leaf;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
error: type 'Tree' is infinitely sized (it contains itself by value); use a pointer ('*Tree') to break the cycle
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user