diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-06-20 11:40:14 -0400 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-06-20 20:09:28 -0700 |
| commit | 8875efe54873b721cc3a6f6d83525b19d1c59ec3 (patch) | |
| tree | cfc48f81d16e591f69bd99a1c7184ebbc1480209 /src/InternPool.zig | |
| parent | 3267eb3a28f6c747772a40beedac14f5feae814f (diff) | |
| download | zig-8875efe54873b721cc3a6f6d83525b19d1c59ec3.tar.gz zig-8875efe54873b721cc3a6f6d83525b19d1c59ec3.zip | |
Sema: fix auto-numbered enums with signed tag types
Closes #16095
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index a385702c43..f92711d4f1 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -443,18 +443,12 @@ pub const Key = union(enum) { return @intCast(u32, field_index); } // Auto-numbered enum. Convert `int_tag_val` to field index. - switch (ip.indexToKey(int_tag_val).int.storage) { - .u64 => |x| { - if (x >= self.names.len) return null; - return @intCast(u32, x); - }, - .i64 => |x| { - if (x >= self.names.len or x < 0) return null; - return @intCast(u32, x); - }, - .big_int => return null, // out of range + const field_index = switch (ip.indexToKey(int_tag_val).int.storage) { + inline .u64, .i64 => |x| std.math.cast(u32, x) orelse return null, + .big_int => |x| x.to(u32) catch return null, .lazy_align, .lazy_size => unreachable, - } + }; + return if (field_index < self.names.len) field_index else null; } }; |
