| author | |
| committer | |
| log | d1fd864da7859989828feb8be806634606cc761c |
| tree | 8d4bcd3470852ecdd9e9edc5810fa1de1fe31174 |
| parent | a5ecffa4617ea5ceed1edfe76b74896e7c249a2d |
isZigPrimitiveType had a bug where it checked the integer names (e.g.
u32) before primitives, leading it to incorrectly return `false` for
`undefined` which starts with `u`.
Related: #99283 files changed, 6 insertions(+), 19 deletions(-)
src/AstGen.zig+4-4| ... | @@ -6540,7 +6540,7 @@ fn identifier( | ... | @@ -6540,7 +6540,7 @@ fn identifier( |
| 6540 | const ident_name = try astgen.identifierTokenString(ident_token); | 6540 | const ident_name = try astgen.identifierTokenString(ident_token); |
| 6541 | 6541 | ||
| 6542 | if (ident_name_raw[0] != '@') { | 6542 | if (ident_name_raw[0] != '@') { |
| 6543 | if (simple_types.get(ident_name)) |zir_const_ref| { | 6543 | if (primitives.get(ident_name)) |zir_const_ref| { |
| 6544 | return rvalue(gz, rl, zir_const_ref, ident); | 6544 | return rvalue(gz, rl, zir_const_ref, ident); |
| 6545 | } | 6545 | } |
| 6546 | 6546 | ||
| ... | @@ -8071,7 +8071,7 @@ fn calleeExpr( | ... | @@ -8071,7 +8071,7 @@ fn calleeExpr( |
| 8071 | } | 8071 | } |
| 8072 | } | 8072 | } |
| 8073 | 8073 | ||
| 8074 | pub const simple_types = std.ComptimeStringMap(Zir.Inst.Ref, .{ | 8074 | const primitives = std.ComptimeStringMap(Zir.Inst.Ref, .{ |
| 8075 | .{ "anyerror", .anyerror_type }, | 8075 | .{ "anyerror", .anyerror_type }, |
| 8076 | .{ "anyframe", .anyframe_type }, | 8076 | .{ "anyframe", .anyframe_type }, |
| 8077 | .{ "bool", .bool_type }, | 8077 | .{ "bool", .bool_type }, |
| ... | @@ -10505,8 +10505,8 @@ fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 { | ... | @@ -10505,8 +10505,8 @@ fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 { |
| 10505 | return @ptrCast([*:0]const u8, astgen.string_bytes.items.ptr) + index; | 10505 | return @ptrCast([*:0]const u8, astgen.string_bytes.items.ptr) + index; |
| 10506 | } | 10506 | } |
| 10507 | 10507 | ||
| 10508 | fn isPrimitive(name: []const u8) bool { | 10508 | pub fn isPrimitive(name: []const u8) bool { |
| 10509 | if (simple_types.get(name) != null) return true; | 10509 | if (primitives.get(name) != null) return true; |
| 10510 | if (name.len < 2) return false; | 10510 | if (name.len < 2) return false; |
| 10511 | const first_c = name[0]; | 10511 | const first_c = name[0]; |
| 10512 | if (first_c != 'i' and first_c != 'u') return false; | 10512 | if (first_c != 'i' and first_c != 'u') return false; |
src/Zir.zig+1-1| ... | @@ -1644,7 +1644,7 @@ pub const Inst = struct { | ... | @@ -1644,7 +1644,7 @@ pub const Inst = struct { |
| 1644 | /// be derived by subtracting `typed_value_map.len`. | 1644 | /// be derived by subtracting `typed_value_map.len`. |
| 1645 | /// | 1645 | /// |
| 1646 | /// When adding a tag to this enum, consider adding a corresponding entry to | 1646 | /// When adding a tag to this enum, consider adding a corresponding entry to |
| 1647 | /// `simple_types` in astgen. | 1647 | /// `primitives` in astgen. |
| 1648 | /// | 1648 | /// |
| 1649 | /// The tag type is specified so that it is safe to bitcast between `[]u32` | 1649 | /// The tag type is specified so that it is safe to bitcast between `[]u32` |
| 1650 | /// and `[]Ref`. | 1650 | /// and `[]Ref`. |
src/translate_c/ast.zig+1-14| ... | @@ -804,21 +804,8 @@ const Context = struct { | ... | @@ -804,21 +804,8 @@ const Context = struct { |
| 804 | return c.addTokenFmt(tag, "{s}", .{bytes}); | 804 | return c.addTokenFmt(tag, "{s}", .{bytes}); |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | fn isZigPrimitiveType(name: []const u8) bool { | ||
| 808 | if (name.len > 1 and (name[0] == 'u' or name[0] == 'i')) { | ||
| 809 | for (name[1..]) |c| { | ||
| 810 | switch (c) { | ||
| 811 | '0'...'9' => {}, | ||
| 812 | else => return false, | ||
| 813 | } | ||
| 814 | } | ||
| 815 | return true; | ||
| 816 | } | ||
| 817 | return @import("../AstGen.zig").simple_types.has(name); | ||
| 818 | } | ||
| 819 | |||
| 820 | fn addIdentifier(c: *Context, bytes: []const u8) Allocator.Error!TokenIndex { | 807 | fn addIdentifier(c: *Context, bytes: []const u8) Allocator.Error!TokenIndex { |
| 821 | if (isZigPrimitiveType(bytes)) | 808 | if (@import("../AstGen.zig").isPrimitive(bytes)) |
| 822 | return c.addTokenFmt(.identifier, "@\"{s}\"", .{bytes}); | 809 | return c.addTokenFmt(.identifier, "@\"{s}\"", .{bytes}); |
| 823 | return c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(bytes)}); | 810 | return c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(bytes)}); |
| 824 | } | 811 | } |