diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-23 14:26:01 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-23 15:40:12 +0300 |
| commit | baf516218e227a55b59c9ae9e6c52b0f9ebd0980 (patch) | |
| tree | d5e983c4efab7d627916b452919e634e007dfee5 /src | |
| parent | 2436dd2c1b976f5902be6d20a93c164631ce3df5 (diff) | |
| download | zig-baf516218e227a55b59c9ae9e6c52b0f9ebd0980.tar.gz zig-baf516218e227a55b59c9ae9e6c52b0f9ebd0980.zip | |
Sema: don't add union field access safety check for single field unions
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index d23487a5fd..db3cfa6d40 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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); |
