mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
Sema: don't add union field access safety check for single field unions
This commit is contained in:
parent
2436dd2c1b
commit
baf516218e
@ -20203,7 +20203,9 @@ fn unionFieldPtr(
|
||||
}
|
||||
|
||||
try sema.requireRuntimeBlock(block, src, null);
|
||||
if (!initializing and union_obj.layout == .Auto and block.wantSafety() and union_ty.unionTagTypeSafety() != null) {
|
||||
if (!initializing and union_obj.layout == .Auto and block.wantSafety() and
|
||||
union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1)
|
||||
{
|
||||
const enum_ty = union_ty.unionTagTypeHypothetical();
|
||||
const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
|
||||
const wanted_tag = try sema.addConstant(enum_ty, wanted_tag_val);
|
||||
@ -20271,7 +20273,9 @@ fn unionFieldVal(
|
||||
}
|
||||
|
||||
try sema.requireRuntimeBlock(block, src, null);
|
||||
if (union_obj.layout == .Auto and block.wantSafety() and union_ty.unionTagTypeSafety() != null) {
|
||||
if (union_obj.layout == .Auto and block.wantSafety() and
|
||||
union_ty.unionTagTypeSafety() != null and union_obj.fields.count() > 1)
|
||||
{
|
||||
const enum_ty = union_ty.unionTagTypeHypothetical();
|
||||
const wanted_tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
|
||||
const wanted_tag = try sema.addConstant(enum_ty, wanted_tag_val);
|
||||
|
||||
@ -222,6 +222,7 @@ fn testBytesAlign(b: u8) !void {
|
||||
test "@alignCast slices" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
|
||||
var array align(4) = [_]u32{ 1, 1 };
|
||||
const slice = array[0..];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user