aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-07-11 19:57:41 +0300
committerVeikka Tuominen <git@vexu.eu>2022-07-11 20:30:16 +0300
commit122c76a1670e4b925ccdabaa771f59e5df6d43aa (patch)
tree3649a70bb7e967af3818d64c250e413a04c107f7 /src
parentd00da05ecbeca36e8ca25dcb1238bf98b38081a5 (diff)
downloadzig-122c76a1670e4b925ccdabaa771f59e5df6d43aa.tar.gz
zig-122c76a1670e4b925ccdabaa771f59e5df6d43aa.zip
Sema: allow `void` as an extern union field & fix invalid extern unions
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 48cab0f04c..d66c447e7c 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -18192,6 +18192,7 @@ fn explainWhyTypeIsComptime(
const ExternPosition = enum {
ret_ty,
param_ty,
+ union_field,
other,
};
@@ -18206,9 +18207,9 @@ fn validateExternType(sema: *Sema, ty: Type, position: ExternPosition) CompileEr
.ErrorUnion,
.ErrorSet,
.BoundFn,
- .Void,
.Frame,
=> return false,
+ .Void => return position == .union_field,
.NoReturn => return position == .ret_ty,
.Opaque,
.Bool,
@@ -24193,13 +24194,13 @@ fn resolveUnionFully(
for (union_obj.fields.values()) |field| {
try sema.resolveTypeFully(block, src, field.ty);
- if (union_obj.layout == .Extern and !(try sema.validateExternType(field.ty, .other))) {
+ if (union_obj.layout == .Extern and !(try sema.validateExternType(field.ty, .union_field))) {
const msg = msg: {
const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field.ty.fmt(sema.mod)});
errdefer msg.destroy(sema.gpa);
const src_decl = sema.mod.declPtr(block.src_decl);
- try sema.explainWhyTypeIsNotExtern(block, src, msg, src.toSrcLoc(src_decl), field.ty, .other);
+ try sema.explainWhyTypeIsNotExtern(block, src, msg, src.toSrcLoc(src_decl), field.ty, .union_field);
try sema.addDeclaredHereNote(msg, field.ty);
break :msg msg;