-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Union with type that has optional field causes segfault in compiler #1995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the stripped down example. |
I see now that it's not supposed to work (but still not supposed to crash of course) because there is a recursive dependency (LhsExpr depends on a non-pointer type of AstObject and AstObject depends on a non-pointer type of LhsExpr). const std = @import("std");
pub const LhsExpr = struct {
rhsExpr: ?AstObject
};
pub const AstObject = union {
lhsExpr: *LhsExpr
};
test "crash" {
var lhsExpr = try std.debug.global_allocator.create(LhsExpr);
const astObj = AstObject {
.lhsExpr = lhsExpr
};
} however this does crash: const std = @import("std");
pub const LhsExpr = struct {
rhsExpr: ?AstObject
};
pub const AstObject = union {
lhsExpr: *LhsExpr
};
test "crash" {
const alignment = @alignOf(AstObject);
} on the other hand |
I think this might be a dupe of #1735 |
Proposal to fix this: #2174 |
Now it gives this:
|
If an union has a type with an optional type then the compiler with crash with segfault.
Example code (stripped down from larger project):
The compiler crashes because it fails to allocate at src/analyze.cpp:2293 (resolve_union_type) because union_type->data.unionation.gen_field_count is 0
The text was updated successfully, but these errors were encountered: