authorgravatar for 58830309+g-w1@users.noreply.github.comg-w1 <58830309+g-w1@users.noreply.github.com> 2021-06-27 05:26:29-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-27 12:26:29+03:00
logef56e42a2a69e85d185257c5bd0b3f12532f2f5d
treeb0620e061d1dea8e894873ec54aee0fcacfd6f66
parent3be682bac9b768ae6481ed2a07844ee8ba87a896
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

stage2: fix unreachable in union(enum) with anytype payload


2 files changed, 6 insertions(+), 2 deletions(-)

src/AstGen.zig+2-2
......@@ -3835,7 +3835,7 @@ fn unionDeclInner(
38353835 if (member.comptime_token) |comptime_token| {
38363836 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});
38373837 }
3838 try fields_data.ensureUnusedCapacity(gpa, 4);
3838 try fields_data.ensureUnusedCapacity(gpa, if (node_tags[member.ast.type_expr] != .@"anytype") 4 else 3);
38393839
38403840 const field_name = try astgen.identAsString(member.ast.name_token);
38413841 fields_data.appendAssumeCapacity(field_name);
......@@ -3850,7 +3850,7 @@ fn unionDeclInner(
38503850 (@as(u32, @boolToInt(have_value)) << 30) |
38513851 (@as(u32, @boolToInt(unused)) << 31);
38523852
3853 if (have_type) {
3853 if (have_type and node_tags[member.ast.type_expr] != .@"anytype") {
38543854 const field_type = try typeExpr(&block_scope, &block_scope.base, member.ast.type_expr);
38553855 fields_data.appendAssumeCapacity(@enumToInt(field_type));
38563856 }
test/behavior/union.zig+4
......@@ -811,3 +811,7 @@ test "union enum type gets a separate scope" {
811811
812812 try S.doTheTest();
813813}
814test "anytype union field: issue #9233" {
815 const Baz = union(enum) { bar: anytype };
816 _ = Baz;
817}