From e7c3afab19a0d9c83b9d5d52184063d4d6501e21 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 7 Mar 2020 21:56:37 +0000 Subject: [PATCH] Prevent non-static fields from overriding other fields I think we have the correct behaviour in all cases now: fields will never override fields. Only non-static methods may override other methods. Signed-off-by: Graham --- .../dev/openrs2/asm/classpath/ClassPath.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt index 5478242d..897f86d8 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt @@ -93,23 +93,31 @@ class ClassPath( } fun createInheritedFieldSets(): DisjointSet { - return createInheritedMemberSets(ClassMetadata::fields, ClassMetadata::getFieldAccess) + return createInheritedMemberSets(ClassMetadata::fields, ClassMetadata::getFieldAccess, fields = true) } fun createInheritedMethodSets(): DisjointSet { - return createInheritedMemberSets(ClassMetadata::methods, ClassMetadata::getMethodAccess) + return createInheritedMemberSets(ClassMetadata::methods, ClassMetadata::getMethodAccess, fields = false) } private fun createInheritedMemberSets( getMembers: (ClassMetadata) -> List, - getMemberAccess: (ClassMetadata, MemberDesc) -> Int? + getMemberAccess: (ClassMetadata, MemberDesc) -> Int?, + fields: Boolean ): DisjointSet { val disjointSet = ForestDisjointSet() val ancestorCache = mutableMapOf>() for (library in libraries) { for (clazz in library) { - populateInheritedMemberSets(getMembers, getMemberAccess, ancestorCache, disjointSet, get(clazz.name)!!) + populateInheritedMemberSets( + getMembers, + getMemberAccess, + fields, + ancestorCache, + disjointSet, + get(clazz.name)!! + ) } } @@ -119,6 +127,7 @@ class ClassPath( private fun populateInheritedMemberSets( getMembers: (ClassMetadata) -> List, getMemberAccess: (ClassMetadata, MemberDesc) -> Int?, + fields: Boolean, ancestorCache: MutableMap>, disjointSet: DisjointSet, clazz: ClassMetadata @@ -132,11 +141,11 @@ class ClassPath( for (superClass in clazz.superClassAndInterfaces) { val members = - populateInheritedMemberSets(getMembers, getMemberAccess, ancestorCache, disjointSet, superClass) + populateInheritedMemberSets(getMembers, getMemberAccess, fields, ancestorCache, disjointSet, superClass) for (member in members) { val access = getMemberAccess(clazz, member) - if (access != null && access and Opcodes.ACC_STATIC != 0) { + if (access != null && (access and Opcodes.ACC_STATIC != 0 || fields)) { continue }