File tree Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -604,28 +604,29 @@ pub fn hasRuntimeBitsInner(
604604 // and then later if our guess was incorrect, we emit a compile error.
605605 if (union_type .assumeRuntimeBitsIfFieldTypesWip (ip )) return true ;
606606 },
607- .safety , .tagged = > {
608- const tag_ty = union_type .tagTypeUnordered (ip );
609- // tag_ty will be `none` if this union's tag type is not resolved yet,
610- // in which case we want control flow to continue down below.
611- if (tag_ty != .none and
612- try Type .fromInterned (tag_ty ).hasRuntimeBitsInner (
613- ignore_comptime_only ,
614- strat ,
615- zcu ,
616- tid ,
617- ))
618- {
619- return true ;
620- }
621- },
607+ .safety , .tagged = > {},
622608 }
623609 switch (strat ) {
624610 .sema = > try ty .resolveFields (strat .pt (zcu , tid )),
625611 .eager = > assert (union_flags .status .haveFieldTypes ()),
626612 .lazy = > if (! union_flags .status .haveFieldTypes ())
627613 return error .NeedLazy ,
628614 }
615+ switch (union_flags .runtime_tag ) {
616+ .none = > {},
617+ .safety , .tagged = > {
618+ const tag_ty = union_type .tagTypeUnordered (ip );
619+ assert (tag_ty != .none ); // tag_ty should have been resolved above
620+ if (try Type .fromInterned (tag_ty ).hasRuntimeBitsInner (
621+ ignore_comptime_only ,
622+ strat ,
623+ zcu ,
624+ tid ,
625+ )) {
626+ return true ;
627+ }
628+ },
629+ }
629630 for (0.. union_type .field_types .len ) | field_index | {
630631 const field_ty = Type .fromInterned (union_type .field_types .get (ip )[field_index ]);
631632 if (try field_ty .hasRuntimeBitsInner (ignore_comptime_only , strat , zcu , tid ))
Original file line number Diff line number Diff line change @@ -1360,6 +1360,14 @@ test "lazy sizeof is resolved in division" {
13601360 try expect (@sizeOf (A ) - a == 2 );
13611361}
13621362
1363+ test "lazy sizeof union tag size in compare" {
1364+ const A = union (enum ) {
1365+ a : void ,
1366+ b : void ,
1367+ };
1368+ try expect (@sizeOf (A ) == 1 );
1369+ }
1370+
13631371test "lazy value is resolved as slice operand" {
13641372 if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ; // TODO
13651373 if (builtin .zig_backend == .stage2_arm ) return error .SkipZigTest ; // TODO
You can’t perform that action at this time.
0 commit comments