-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sema: Prevent reifying non-empty union with empty tag type
- Loading branch information
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/cases/compile_errors/reify_type_for_tagged_union_with_no_enum_fields.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Tag = @Type(.{ | ||
.Enum = .{ | ||
.tag_type = u0, | ||
.fields = &.{}, | ||
.decls = &.{}, | ||
.is_exhaustive = true, | ||
}, | ||
}); | ||
const Tagged = @Type(.{ | ||
.Union = .{ | ||
.layout = .Auto, | ||
.tag_type = Tag, | ||
.fields = &.{ | ||
.{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
.{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
}, | ||
.decls = &.{}, | ||
}, | ||
}); | ||
export fn entry() void { | ||
const tagged: Tagged = undefined; | ||
_ = tagged; | ||
} | ||
|
||
// error | ||
// backend=stage2 | ||
// target=native | ||
// | ||
// :9:16: error: no field named 'signed' in enum 'tmp.Tag' | ||
// :1:13: note: enum declared here |
32 changes: 32 additions & 0 deletions
32
test/cases/compile_errors/reify_type_for_tagged_union_with_no_union_fields.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Tag = @Type(.{ | ||
.Enum = .{ | ||
.tag_type = u1, | ||
.fields = &.{ | ||
.{ .name = "signed", .value = 0 }, | ||
.{ .name = "unsigned", .value = 1 }, | ||
}, | ||
.decls = &.{}, | ||
.is_exhaustive = true, | ||
}, | ||
}); | ||
const Tagged = @Type(.{ | ||
.Union = .{ | ||
.layout = .Auto, | ||
.tag_type = Tag, | ||
.fields = &.{}, | ||
.decls = &.{}, | ||
}, | ||
}); | ||
export fn entry() void { | ||
const tagged: Tagged = undefined; | ||
_ = tagged; | ||
} | ||
|
||
// error | ||
// backend=stage2 | ||
// target=native | ||
// | ||
// :12:16: error: enum field(s) missing in union | ||
// :1:13: note: field 'signed' missing, declared here | ||
// :1:13: note: field 'unsigned' missing, declared here | ||
// :1:13: note: enum declared here |