| author | |
| committer | |
| log | 4911d39769e3b9ccf07062751106aa388bc97e48 |
| tree | 0594deb662f41f4fb404a937e7e6d4902c118081 |
| parent | 4ef1c1c705ceb2d89d0bf93d7a2403c165ae9dc0 |
2 files changed, 24 insertions(+), 1 deletions(-)
src/AstGen.zig+5| ... | @@ -2851,6 +2851,9 @@ fn varDecl( | ... | @@ -2851,6 +2851,9 @@ fn varDecl( |
| 2851 | return &sub_scope.base; | 2851 | return &sub_scope.base; |
| 2852 | }, | 2852 | }, |
| 2853 | .keyword_var => { | 2853 | .keyword_var => { |
| 2854 | const old_rl_ty_inst = gz.rl_ty_inst; | ||
| 2855 | defer gz.rl_ty_inst = old_rl_ty_inst; | ||
| 2856 | |||
| 2854 | const is_comptime = var_decl.comptime_token != null or gz.force_comptime; | 2857 | const is_comptime = var_decl.comptime_token != null or gz.force_comptime; |
| 2855 | var resolve_inferred_alloc: Zir.Inst.Ref = .none; | 2858 | var resolve_inferred_alloc: Zir.Inst.Ref = .none; |
| 2856 | const var_data: struct { | 2859 | const var_data: struct { |
| ... | @@ -2875,6 +2878,7 @@ fn varDecl( | ... | @@ -2875,6 +2878,7 @@ fn varDecl( |
| 2875 | }); | 2878 | }); |
| 2876 | } | 2879 | } |
| 2877 | }; | 2880 | }; |
| 2881 | gz.rl_ty_inst = type_inst; | ||
| 2878 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; | 2882 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; |
| 2879 | } else a: { | 2883 | } else a: { |
| 2880 | const alloc = alloc: { | 2884 | const alloc = alloc: { |
| ... | @@ -2894,6 +2898,7 @@ fn varDecl( | ... | @@ -2894,6 +2898,7 @@ fn varDecl( |
| 2894 | }); | 2898 | }); |
| 2895 | } | 2899 | } |
| 2896 | }; | 2900 | }; |
| 2901 | gz.rl_ty_inst = .none; | ||
| 2897 | resolve_inferred_alloc = alloc; | 2902 | resolve_inferred_alloc = alloc; |
| 2898 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; | 2903 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; |
| 2899 | }; | 2904 | }; |
test/behavior/basic.zig+19-1| ... | @@ -859,7 +859,6 @@ test "catch in block has correct result location" { | ... | @@ -859,7 +859,6 @@ test "catch in block has correct result location" { |
| 859 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 859 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 860 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 860 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 861 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 861 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 862 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | ||
| 863 | 862 | ||
| 864 | const S = struct { | 863 | const S = struct { |
| 865 | fn open() error{A}!@This() { | 864 | fn open() error{A}!@This() { |
| ... | @@ -887,3 +886,22 @@ test "labeled block with runtime branch forwards its result location type to bre | ... | @@ -887,3 +886,22 @@ test "labeled block with runtime branch forwards its result location type to bre |
| 887 | }; | 886 | }; |
| 888 | try expect(e == .b); | 887 | try expect(e == .b); |
| 889 | } | 888 | } |
| 889 | |||
| 890 | test "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 | } |