From ec650b614f7a366621294bc0ca2019e19f7d0025 Mon Sep 17 00:00:00 2001 From: ktkk Date: Tue, 23 Jun 2026 20:53:55 +0200 Subject: [PATCH] Perform more checks on superclass --- src/Class.zig | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Class.zig b/src/Class.zig index 3d8175a..69ef748 100644 --- a/src/Class.zig +++ b/src/Class.zig @@ -290,20 +290,23 @@ pub fn thisClass(self: *const Self) ResolveError!CpInfo { } pub fn superClass(self: *const Self) ResolveError!?CpInfo { - // TODO: Determine whether this is an interface or a regular class. - // When this is an interface, assert that the super class must be Object. - if (self.super_class == 0) { const this_class = (try self.thisClass()).class; const this_class_name = (try this_class.name(self.constant_pool)).utf8; - if (!std.mem.eql(u8, this_class_name.bytes, "Object")) return ResolveError.InvalidConstantType; + if (!std.mem.eql(u8, this_class_name.bytes, "java/lang/Object")) return ResolveError.InvalidConstantType; return null; } else { const super_class = self.super_class - 1; if (super_class >= self.constant_pool.len) return ResolveError.InvalidConstantPoolIndex; const cp_info = self.constant_pool[super_class]; if (cp_info == null or @as(CpInfo.Tag, cp_info.?) != .class) return ResolveError.InvalidConstantType; - // TODO: Assert that superclass does not have ACC_FINAL flag set. + + if (self.access_flags.contains(.interface)) { + const super_class_name = (try cp_info.?.class.name(self.constant_pool)).utf8; + if (!std.mem.eql(u8, super_class_name.bytes, "java/lang/Object")) return ResolveError.InvalidConstantType; + } else { + // TODO: Assert that superclass does not have ACC_FINAL flag set. + } return cp_info.?; } }