| author | |
| committer | |
| log | 1799455e0587644c98cdba67bd10a59a2d45b116 |
| tree | 6539087c26b1984a0fc3ed391efdb1955d79bf01 |
| parent | 759d1d9aeffbe1c5eaf7d5675b6d1c165757cdf1 |
2 files changed, 30 insertions(+), 0 deletions(-)
src/AstGen.zig+3| ... | ... | @@ -5008,6 +5008,7 @@ fn ifExpr( |
| 5008 | 5008 | const token_name_str = tree.tokenSlice(token_name_index); |
| 5009 | 5009 | if (mem.eql(u8, "_", token_name_str)) |
| 5010 | 5010 | break :s &then_scope.base; |
| 5011 | try astgen.detectLocalShadowing(&then_scope.base, ident_name, token_name_index); | |
| 5011 | 5012 | payload_val_scope = .{ |
| 5012 | 5013 | .parent = &then_scope.base, |
| 5013 | 5014 | .gen_zir = &then_scope, |
| ... | ... | @@ -5030,6 +5031,7 @@ fn ifExpr( |
| 5030 | 5031 | break :s &then_scope.base; |
| 5031 | 5032 | const payload_inst = try then_scope.addUnNode(tag, cond.inst, node); |
| 5032 | 5033 | const ident_name = try astgen.identAsString(ident_token); |
| 5034 | try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token); | |
| 5033 | 5035 | payload_val_scope = .{ |
| 5034 | 5036 | .parent = &then_scope.base, |
| 5035 | 5037 | .gen_zir = &then_scope, |
| ... | ... | @@ -5071,6 +5073,7 @@ fn ifExpr( |
| 5071 | 5073 | const error_token_str = tree.tokenSlice(error_token); |
| 5072 | 5074 | if (mem.eql(u8, "_", error_token_str)) |
| 5073 | 5075 | break :s &else_scope.base; |
| 5076 | try astgen.detectLocalShadowing(&else_scope.base, ident_name, error_token); | |
| 5074 | 5077 | payload_val_scope = .{ |
| 5075 | 5078 | .parent = &else_scope.base, |
| 5076 | 5079 | .gen_zir = &else_scope, |
test/cases.zig+27| ... | ... | @@ -1108,6 +1108,33 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1108 | 1108 | ":5:13: error: redeclaration of local variable 'i'", |
| 1109 | 1109 | ":2:9: note: previous declaration here", |
| 1110 | 1110 | }); |
| 1111 | case.addError( | |
| 1112 | \\pub fn main() void { | |
| 1113 | \\ var i = 0; | |
| 1114 | \\ if (true) |i| {} | |
| 1115 | \\} | |
| 1116 | , &[_][]const u8{ | |
| 1117 | ":3:16: error: redeclaration of local variable 'i'", | |
| 1118 | ":2:9: note: previous declaration here", | |
| 1119 | }); | |
| 1120 | case.addError( | |
| 1121 | \\pub fn main() void { | |
| 1122 | \\ var i = 0; | |
| 1123 | \\ if (true) |i| {} else |e| {} | |
| 1124 | \\} | |
| 1125 | , &[_][]const u8{ | |
| 1126 | ":3:16: error: redeclaration of local variable 'i'", | |
| 1127 | ":2:9: note: previous declaration here", | |
| 1128 | }); | |
| 1129 | case.addError( | |
| 1130 | \\pub fn main() void { | |
| 1131 | \\ var i = 0; | |
| 1132 | \\ if (true) |_| {} else |i| {} | |
| 1133 | \\} | |
| 1134 | , &[_][]const u8{ | |
| 1135 | ":3:28: error: redeclaration of local variable 'i'", | |
| 1136 | ":2:9: note: previous declaration here", | |
| 1137 | }); | |
| 1111 | 1138 | } |
| 1112 | 1139 | |
| 1113 | 1140 | { |