| author | |
| committer | |
| log | 54e7f58fcb8cd3fbfd1b1a3efd090c296b0e728b |
| tree | f53eeea31e8226da6e2b581ababcb0b3e0dc263f |
| parent | 1de242cd732b63bbd8b24579b42b0ccfaf40e193 |
| parent | 9402f8b74aca76a14c7e9d00fd917e8ae9a02d2f |
| signature |
wasm - fix `@tagName` for signed enums2 files changed, 18 insertions(+), 2 deletions(-)
src/arch/wasm/CodeGen.zig+2-2| ... | @@ -7215,12 +7215,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | ... | @@ -7215,12 +7215,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7215 | switch (tag_value) { | 7215 | switch (tag_value) { |
| 7216 | .imm32 => |value| { | 7216 | .imm32 => |value| { |
| 7217 | try writer.writeByte(std.wasm.opcode(.i32_const)); | 7217 | try writer.writeByte(std.wasm.opcode(.i32_const)); |
| 7218 | try leb.writeULEB128(writer, value); | 7218 | try leb.writeILEB128(writer, @as(i32, @bitCast(value))); |
| 7219 | try writer.writeByte(std.wasm.opcode(.i32_ne)); | 7219 | try writer.writeByte(std.wasm.opcode(.i32_ne)); |
| 7220 | }, | 7220 | }, |
| 7221 | .imm64 => |value| { | 7221 | .imm64 => |value| { |
| 7222 | try writer.writeByte(std.wasm.opcode(.i64_const)); | 7222 | try writer.writeByte(std.wasm.opcode(.i64_const)); |
| 7223 | try leb.writeULEB128(writer, value); | 7223 | try leb.writeILEB128(writer, @as(i64, @bitCast(value))); |
| 7224 | try writer.writeByte(std.wasm.opcode(.i64_ne)); | 7224 | try writer.writeByte(std.wasm.opcode(.i64_ne)); |
| 7225 | }, | 7225 | }, |
| 7226 | else => unreachable, | 7226 | else => unreachable, |
test/behavior/enum.zig+16| ... | @@ -1048,6 +1048,22 @@ test "@tagName on enum literals" { | ... | @@ -1048,6 +1048,22 @@ test "@tagName on enum literals" { |
| 1048 | try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | 1048 | try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); |
| 1049 | } | 1049 | } |
| 1050 | 1050 | ||
| 1051 | test "tag name with signed enum values" { | ||
| 1052 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 1053 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 1054 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1055 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1056 | |||
| 1057 | const LocalFoo = enum(isize) { | ||
| 1058 | alfa = 62, | ||
| 1059 | bravo = 63, | ||
| 1060 | charlie = 64, | ||
| 1061 | delta = 65, | ||
| 1062 | }; | ||
| 1063 | var b = LocalFoo.bravo; | ||
| 1064 | try expect(mem.eql(u8, @tagName(b), "bravo")); | ||
| 1065 | } | ||
| 1066 | |||
| 1051 | test "enum literal casting to optional" { | 1067 | test "enum literal casting to optional" { |
| 1052 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 1068 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 1053 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 1069 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |