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(...@@ -3835,7 +3835,7 @@ fn unionDeclInner(
3835 if (member.comptime_token) |comptime_token| {3835 if (member.comptime_token) |comptime_token| {
3836 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});3836 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});
3837 }3837 }
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
3840 const field_name = try astgen.identAsString(member.ast.name_token);3840 const field_name = try astgen.identAsString(member.ast.name_token);
3841 fields_data.appendAssumeCapacity(field_name);3841 fields_data.appendAssumeCapacity(field_name);
...@@ -3850,7 +3850,7 @@ fn unionDeclInner(...@@ -3850,7 +3850,7 @@ fn unionDeclInner(
3850 (@as(u32, @boolToInt(have_value)) << 30) |3850 (@as(u32, @boolToInt(have_value)) << 30) |
3851 (@as(u32, @boolToInt(unused)) << 31);3851 (@as(u32, @boolToInt(unused)) << 31);
38523852
3853 if (have_type) {3853 if (have_type and node_tags[member.ast.type_expr] != .@"anytype") {
3854 const field_type = try typeExpr(&block_scope, &block_scope.base, member.ast.type_expr);3854 const field_type = try typeExpr(&block_scope, &block_scope.base, member.ast.type_expr);
3855 fields_data.appendAssumeCapacity(@enumToInt(field_type));3855 fields_data.appendAssumeCapacity(@enumToInt(field_type));
3856 }3856 }
test/behavior/union.zig+4
...@@ -811,3 +811,7 @@ test "union enum type gets a separate scope" {...@@ -811,3 +811,7 @@ test "union enum type gets a separate scope" {
811811
812 try S.doTheTest();812 try S.doTheTest();
813}813}
814test "anytype union field: issue #9233" {
815 const Baz = union(enum) { bar: anytype };
816 _ = Baz;
817}