Perform more checks on superclass

This commit is contained in:
ktkk 2026-06-23 20:53:55 +02:00
parent e04cc8cc66
commit ec650b614f

View file

@ -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.?;
}
}