| ... | @@ -135,12 +135,13 @@ const Scope = struct { | ... | @@ -135,12 +135,13 @@ const Scope = struct { |
| 135 | /// Given the desired name, return a name that does not shadow anything from outer scopes. | 135 | /// Given the desired name, return a name that does not shadow anything from outer scopes. |
| 136 | /// Inserts the returned name into the scope. | 136 | /// Inserts the returned name into the scope. |
| 137 | fn makeMangledName(scope: *Block, c: *Context, name: []const u8) ![]const u8 { | 137 | fn makeMangledName(scope: *Block, c: *Context, name: []const u8) ![]const u8 { |
| 138 | var proposed_name = name; | 138 | const name_copy = try c.arena.dupe(u8, name); |
| | 139 | var proposed_name = name_copy; |
| 139 | while (scope.contains(proposed_name)) { | 140 | while (scope.contains(proposed_name)) { |
| 140 | scope.mangle_count += 1; | 141 | scope.mangle_count += 1; |
| 141 | proposed_name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ name, scope.mangle_count }); | 142 | proposed_name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ name, scope.mangle_count }); |
| 142 | } | 143 | } |
| 143 | try scope.variables.append(.{ .name = name, .alias = proposed_name }); | 144 | try scope.variables.append(.{ .name = name_copy, .alias = proposed_name }); |
| 144 | return proposed_name; | 145 | return proposed_name; |
| 145 | } | 146 | } |
| 146 | | 147 | |