From cb43efcbb14a0b703745390c6399016c707acff3 Mon Sep 17 00:00:00 2001 From: ktkk Date: Mon, 6 Jul 2026 08:52:12 +0000 Subject: [PATCH] Add `is` method to ConstantPool.Info --- src/Class/ConstantPool.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Class/ConstantPool.zig b/src/Class/ConstantPool.zig index 17e71c2..6c5afe3 100644 --- a/src/Class/ConstantPool.zig +++ b/src/Class/ConstantPool.zig @@ -165,15 +165,15 @@ pub const Info = union(Info.Tag) { const info = try constant_pool.get(self.reference_index); return switch (self.reference_kind) { .get_field, .get_static, .put_field, .put_static => blk: { - if (@as(Tag, info) != .field_ref) break :blk ResolveError.InvalidConstantType; + if (!info.is(.field_ref)) break :blk ResolveError.InvalidConstantType; break :blk info; }, .invoke_virtual, .invoke_static, .invoke_special, .new_invoke_special => blk: { - if (@as(Tag, info) != .method_ref) break :blk ResolveError.InvalidConstantType; + if (!info.is(.method_ref)) break :blk ResolveError.InvalidConstantType; break :blk info; }, .invoke_interface => blk: { - if (@as(Tag, info) != .interface_method_ref) break :blk ResolveError.InvalidConstantType; + if (!info.is(.interface_method_ref)) break :blk ResolveError.InvalidConstantType; break :blk info; }, }; @@ -496,6 +496,10 @@ pub const Info = union(Info.Tag) { }, } } + + pub fn is(self: *const Info, tag: Tag) bool { + return @as(Tag, self.*) == tag; + } }; pub fn parse(input: *std.Io.Reader, allocator: std.mem.Allocator) ParseError!Self { @@ -546,7 +550,7 @@ pub fn getOptional(self: *const Self, index: u16) ResolveError!?Info { pub fn getTag(self: *const Self, index: u16, expected_tag: Info.Tag) ResolveError!Info { const info = try self.get(index); - if (@as(Info.Tag, info) != expected_tag) return ResolveError.InvalidConstantType; + if (!info.is(expected_tag)) return ResolveError.InvalidConstantType; return info; }