File tree 2 files changed +18
-2
lines changed 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -22475,7 +22475,10 @@ fn fieldVal(
22475
22475
} else (try sema.mod.getErrorValue(field_name)).key;
22476
22476
22477
22477
return sema.addConstant(
22478
- try child_type.copy(arena),
22478
+ if (!child_type.isAnyError())
22479
+ try child_type.copy(arena)
22480
+ else
22481
+ try Type.Tag.error_set_single.create(arena, name),
22479
22482
try Value.Tag.@"error".create(arena, .{ .name = name }),
22480
22483
);
22481
22484
},
@@ -22686,7 +22689,10 @@ fn fieldPtr(
22686
22689
var anon_decl = try block.startAnonDecl(src);
22687
22690
defer anon_decl.deinit();
22688
22691
return sema.analyzeDeclRef(try anon_decl.finish(
22689
- try child_type.copy(anon_decl.arena()),
22692
+ if (!child_type.isAnyError())
22693
+ try child_type.copy(anon_decl.arena())
22694
+ else
22695
+ try Type.Tag.error_set_single.create(anon_decl.arena(), name),
22690
22696
try Value.Tag.@"error".create(anon_decl.arena(), .{ .name = name }),
22691
22697
0, // default alignment
22692
22698
));
Original file line number Diff line number Diff line change @@ -855,3 +855,13 @@ test "error from comptime string" {
855
855
try expect (mem .eql (u8 , name , @errorName (err )));
856
856
}
857
857
}
858
+
859
+ test "field access of anyerror results in smaller error set" {
860
+ if (builtin .zig_backend == .stage1 ) return error .SkipZigTest ;
861
+
862
+ const E1 = @TypeOf (error .Foo );
863
+ try expect (@TypeOf (E1 .Foo ) == E1 );
864
+ const E2 = error { A , B , C };
865
+ try expect (@TypeOf (E2 .A ) == E2 );
866
+ try expect (@TypeOf (@field (anyerror , "NotFound" )) == error {NotFound });
867
+ }
You can’t perform that action at this time.
0 commit comments