| author | |
| committer | |
| log | 9d4561ef0082728bbba085e8a4689ccc93a37b27 |
| tree | 8bb2dd3845b94629b49c0a778999d9dcdf2a9f47 |
| parent | c17793b4875cc9e1ccb605431142ffecb0b6f3f2 |
Closes #93554 files changed, 71 insertions(+), 9 deletions(-)
lib/std/bounded_array.zig+7-7| ... | @@ -15,16 +15,16 @@ const testing = std.testing; | ... | @@ -15,16 +15,16 @@ const testing = std.testing; |
| 15 | /// var slice = a.slice(); // a slice of the 64-byte array | 15 | /// var slice = a.slice(); // a slice of the 64-byte array |
| 16 | /// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers | 16 | /// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers |
| 17 | /// ``` | 17 | /// ``` |
| 18 | pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { | 18 | pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { |
| 19 | return struct { | 19 | return struct { |
| 20 | const Self = @This(); | 20 | const Self = @This(); |
| 21 | buffer: [capacity]T = undefined, | 21 | buffer: [buffer_capacity]T = undefined, |
| 22 | len: usize = 0, | 22 | len: usize = 0, |
| 23 | 23 | ||
| 24 | /// Set the actual length of the slice. | 24 | /// Set the actual length of the slice. |
| 25 | /// Returns error.Overflow if it exceeds the length of the backing array. | 25 | /// Returns error.Overflow if it exceeds the length of the backing array. |
| 26 | pub fn init(len: usize) error{Overflow}!Self { | 26 | pub fn init(len: usize) error{Overflow}!Self { |
| 27 | if (len > capacity) return error.Overflow; | 27 | if (len > buffer_capacity) return error.Overflow; |
| 28 | return Self{ .len = len }; | 28 | return Self{ .len = len }; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| ... | @@ -41,7 +41,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { | ... | @@ -41,7 +41,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { |
| 41 | /// Adjust the slice's length to `len`. | 41 | /// Adjust the slice's length to `len`. |
| 42 | /// Does not initialize added items if any. | 42 | /// Does not initialize added items if any. |
| 43 | pub fn resize(self: *Self, len: usize) error{Overflow}!void { | 43 | pub fn resize(self: *Self, len: usize) error{Overflow}!void { |
| 44 | if (len > capacity) return error.Overflow; | 44 | if (len > buffer_capacity) return error.Overflow; |
| 45 | self.len = len; | 45 | self.len = len; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| ... | @@ -69,7 +69,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { | ... | @@ -69,7 +69,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { |
| 69 | 69 | ||
| 70 | /// Check that the slice can hold at least `additional_count` items. | 70 | /// Check that the slice can hold at least `additional_count` items. |
| 71 | pub fn ensureUnusedCapacity(self: Self, additional_count: usize) error{Overflow}!void { | 71 | pub fn ensureUnusedCapacity(self: Self, additional_count: usize) error{Overflow}!void { |
| 72 | if (self.len + additional_count > capacity) { | 72 | if (self.len + additional_count > buffer_capacity) { |
| 73 | return error.Overflow; | 73 | return error.Overflow; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| ... | @@ -83,7 +83,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { | ... | @@ -83,7 +83,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { |
| 83 | /// Increase length by 1, returning pointer to the new item. | 83 | /// Increase length by 1, returning pointer to the new item. |
| 84 | /// Asserts that there is space for the new item. | 84 | /// Asserts that there is space for the new item. |
| 85 | pub fn addOneAssumeCapacity(self: *Self) *T { | 85 | pub fn addOneAssumeCapacity(self: *Self) *T { |
| 86 | assert(self.len < capacity); | 86 | assert(self.len < buffer_capacity); |
| 87 | self.len += 1; | 87 | self.len += 1; |
| 88 | return &self.slice()[self.len - 1]; | 88 | return &self.slice()[self.len - 1]; |
| 89 | } | 89 | } |
| ... | @@ -236,7 +236,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { | ... | @@ -236,7 +236,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { |
| 236 | pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { | 236 | pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { |
| 237 | const old_len = self.len; | 237 | const old_len = self.len; |
| 238 | self.len += n; | 238 | self.len += n; |
| 239 | assert(self.len <= capacity); | 239 | assert(self.len <= buffer_capacity); |
| 240 | mem.set(T, self.slice()[old_len..self.len], value); | 240 | mem.set(T, self.slice()[old_len..self.len], value); |
| 241 | } | 241 | } |
| 242 | 242 |
lib/std/debug.zig+2-2| ... | @@ -1947,7 +1947,7 @@ noinline fn showMyTrace() usize { | ... | @@ -1947,7 +1947,7 @@ noinline fn showMyTrace() usize { |
| 1947 | /// For more advanced usage, see `ConfigurableTrace`. | 1947 | /// For more advanced usage, see `ConfigurableTrace`. |
| 1948 | pub const Trace = ConfigurableTrace(2, 4, builtin.mode == .Debug); | 1948 | pub const Trace = ConfigurableTrace(2, 4, builtin.mode == .Debug); |
| 1949 | 1949 | ||
| 1950 | pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize, comptime enabled: bool) type { | 1950 | pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize, comptime is_enabled: bool) type { |
| 1951 | return struct { | 1951 | return struct { |
| 1952 | addrs: [actual_size][stack_frame_count]usize = undefined, | 1952 | addrs: [actual_size][stack_frame_count]usize = undefined, |
| 1953 | notes: [actual_size][]const u8 = undefined, | 1953 | notes: [actual_size][]const u8 = undefined, |
| ... | @@ -1956,7 +1956,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize | ... | @@ -1956,7 +1956,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize |
| 1956 | const actual_size = if (enabled) size else 0; | 1956 | const actual_size = if (enabled) size else 0; |
| 1957 | const Index = if (enabled) usize else u0; | 1957 | const Index = if (enabled) usize else u0; |
| 1958 | 1958 | ||
| 1959 | pub const enabled = enabled; | 1959 | pub const enabled = is_enabled; |
| 1960 | 1960 | ||
| 1961 | pub const add = if (enabled) addNoInline else addNoOp; | 1961 | pub const add = if (enabled) addNoInline else addNoOp; |
| 1962 | 1962 |
src/AstGen.zig+40| ... | @@ -11751,6 +11751,46 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast. | ... | @@ -11751,6 +11751,46 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast. |
| 11751 | error.OutOfMemory => return error.OutOfMemory, | 11751 | error.OutOfMemory => return error.OutOfMemory, |
| 11752 | } | 11752 | } |
| 11753 | } | 11753 | } |
| 11754 | |||
| 11755 | // const index_name = try astgen.identAsString(index_token); | ||
| 11756 | var s = namespace.parent; | ||
| 11757 | while (true) switch (s.tag) { | ||
| 11758 | .local_val => { | ||
| 11759 | const local_val = s.cast(Scope.LocalVal).?; | ||
| 11760 | if (local_val.name == name_str_index) { | ||
| 11761 | return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{ | ||
| 11762 | @tagName(local_val.id_cat), token_bytes, | ||
| 11763 | }, &[_]u32{ | ||
| 11764 | try astgen.errNoteTok( | ||
| 11765 | local_val.token_src, | ||
| 11766 | "previous declaration here", | ||
| 11767 | .{}, | ||
| 11768 | ), | ||
| 11769 | }); | ||
| 11770 | } | ||
| 11771 | s = local_val.parent; | ||
| 11772 | }, | ||
| 11773 | .local_ptr => { | ||
| 11774 | const local_ptr = s.cast(Scope.LocalPtr).?; | ||
| 11775 | if (local_ptr.name == name_str_index) { | ||
| 11776 | return astgen.failTokNotes(name_token, "redeclaration of {s} '{s}'", .{ | ||
| 11777 | @tagName(local_ptr.id_cat), token_bytes, | ||
| 11778 | }, &[_]u32{ | ||
| 11779 | try astgen.errNoteTok( | ||
| 11780 | local_ptr.token_src, | ||
| 11781 | "previous declaration here", | ||
| 11782 | .{}, | ||
| 11783 | ), | ||
| 11784 | }); | ||
| 11785 | } | ||
| 11786 | s = local_ptr.parent; | ||
| 11787 | }, | ||
| 11788 | .namespace => s = s.cast(Scope.Namespace).?.parent, | ||
| 11789 | .gen_zir => s = s.cast(GenZir).?.parent, | ||
| 11790 | .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, | ||
| 11791 | .defer_gen => s = s.cast(Scope.DeferGen).?.parent, | ||
| 11792 | .top => break, | ||
| 11793 | }; | ||
| 11754 | gop.value_ptr.* = member_node; | 11794 | gop.value_ptr.* = member_node; |
| 11755 | } | 11795 | } |
| 11756 | return decl_count; | 11796 | return decl_count; |
test/cases/compile_errors/decl_shadows_local.zig created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | fn foo(a: usize) void { | ||
| 2 | struct { | ||
| 3 | const a = 1; | ||
| 4 | }; | ||
| 5 | } | ||
| 6 | fn bar(a: usize) void { | ||
| 7 | struct { | ||
| 8 | const b = struct { | ||
| 9 | const a = 1; | ||
| 10 | }; | ||
| 11 | }; | ||
| 12 | _ = a; | ||
| 13 | } | ||
| 14 | |||
| 15 | // error | ||
| 16 | // backend=stage2 | ||
| 17 | // target=native | ||
| 18 | // | ||
| 19 | // :3:15: error: redeclaration of function parameter 'a' | ||
| 20 | // :1:8: note: previous declaration here | ||
| 21 | // :9:19: error: redeclaration of function parameter 'a' | ||
| 22 | // :6:8: note: previous declaration here | ||