Skip to content

Some union fixes #24275

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29442,8 +29442,6 @@ fn coerceExtra(
if (maybe_inst_val) |val| if (val.toIntern() == .undef) return pt.undefRef(dest_ty);
}

if (!opts.report_err) return error.NotCoercible;

if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .noreturn) {
const msg = msg: {
const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{});
Expand All @@ -29459,6 +29457,8 @@ fn coerceExtra(
return sema.failWithOwnedErrorMsg(block, msg);
}

if (!opts.report_err) return error.NotCoercible;

const msg = msg: {
const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), inst_ty.fmt(pt) });
errdefer msg.destroy(sema.gpa);
Expand Down Expand Up @@ -36141,6 +36141,11 @@ fn unionFields(
};
return sema.failWithOwnedErrorMsg(&block_scope, msg);
}
} else if (!small.auto_enum_tag and tag_type_ref != .none) {
const tag_ty = union_type.tagTypeUnordered(ip);
return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
field_name.fmt(ip), Type.fromInterned(tag_ty).fmt(pt),
});
}

if (field_ty.zigTypeTag(zcu) == .@"opaque") {
Expand Down
2 changes: 1 addition & 1 deletion src/link/Dwarf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
const field_type: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
try wip_nav.refType(field_type);
try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
field_type.abiAlignment(zcu).toByteUnits().?);
if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
break :tag .done;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const E = enum {};
const U = union(E) {
one,
two,
};

pub fn main() void {
_ = U.one;
}

// error
// backend=stage2
// target=native
//
// :3:5: error: no field named 'one' in enum 'tmp.E'
// :1:11: note: enum declared here