From a102bffbb44db909276caac1e4a22efc208633db Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Thu, 4 Apr 2024 19:06:45 +0200 Subject: [PATCH] Fixes incorrect field resolution in base classes (#1490) Due to a bug in the symbol resolver, we did not resolve fields that are in base classes of classes incorrectly --- .../kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt | 4 ++-- .../de/fraunhofer/aisec/cpg/passes/TypeHierarchyResolver.kt | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt index 3edf2cb4d7..a85c78da84 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt @@ -399,8 +399,8 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) { if (member == null) { member = containingClass.superTypes - .flatMap { it.fields } - .filter { it.name.lastPartsMatch(reference.name) } + .flatMap { it.recordDeclaration?.fields ?: listOf() } + .filter { it.name.localName == reference.name.localName } .map { it.definition } .firstOrNull() } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/TypeHierarchyResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/TypeHierarchyResolver.kt index d070a6912e..d3d96bd731 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/TypeHierarchyResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/TypeHierarchyResolver.kt @@ -109,6 +109,11 @@ open class TypeHierarchyResolver(ctx: TranslationContext) : ComponentPass(ctx) { .mapNotNull { (it as? ObjectType)?.recordDeclaration } .toSet() recordDeclaration.superTypeDeclarations = superTypeDeclarations + + // This will make sure that the type is correctly registered with the type system and that + // all the super types are set correctly + recordDeclaration.toType() + return superTypeDeclarations }