authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-04-15 10:41:35+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-04-15 11:17:06+03:00
log4911d39769e3b9ccf07062751106aa388bc97e48
tree0594deb662f41f4fb404a937e7e6d4902c118081
parent4ef1c1c705ceb2d89d0bf93d7a2403c165ae9dc0

AstGen: handle rl_ty_inst for mutable variables


2 files changed, 24 insertions(+), 1 deletions(-)

src/AstGen.zig+5
......@@ -2851,6 +2851,9 @@ fn varDecl(
28512851 return &sub_scope.base;
28522852 },
28532853 .keyword_var => {
2854 const old_rl_ty_inst = gz.rl_ty_inst;
2855 defer gz.rl_ty_inst = old_rl_ty_inst;
2856
28542857 const is_comptime = var_decl.comptime_token != null or gz.force_comptime;
28552858 var resolve_inferred_alloc: Zir.Inst.Ref = .none;
28562859 const var_data: struct {
......@@ -2875,6 +2878,7 @@ fn varDecl(
28752878 });
28762879 }
28772880 };
2881 gz.rl_ty_inst = type_inst;
28782882 break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } };
28792883 } else a: {
28802884 const alloc = alloc: {
......@@ -2894,6 +2898,7 @@ fn varDecl(
28942898 });
28952899 }
28962900 };
2901 gz.rl_ty_inst = .none;
28972902 resolve_inferred_alloc = alloc;
28982903 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
28992904 };
test/behavior/basic.zig+19-1
......@@ -859,7 +859,6 @@ test "catch in block has correct result location" {
859859 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
860860 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
861861 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
862 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
863862
864863 const S = struct {
865864 fn open() error{A}!@This() {
......@@ -887,3 +886,22 @@ test "labeled block with runtime branch forwards its result location type to bre
887886 };
888887 try expect(e == .b);
889888}
889
890test "try in labeled block doesn't cast to wrong type" {
891 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
892 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
893
894 const S = struct {
895 a: u32,
896 fn foo() anyerror!u32 {
897 return 1;
898 }
899 };
900 const s: ?*S = blk: {
901 var a = try S.foo();
902
903 _ = a;
904 break :blk null;
905 };
906 _ = s;
907}