From 4b71b704ae33b8b3c31c5c8147adbacc0f410627 Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Mon, 29 Jun 2026 10:13:40 +0200 Subject: [PATCH] Kotlin extractor: keep synthetic locations for unresolved file classes Why this is needed: - library-tests/multiple_files/method_accesses.ql regressed because receiver class locations for external file-class members became concrete file paths. - For stdlib-style unresolved container-source paths, forcing a concrete location changed stable output from synthetic unknown location to external path-based locations. What changed: - Added shouldUseConcreteExternalFileClassLocation to distinguish reliable concrete paths from unresolved placeholders. - In external package-fragment parent handling, only write an external file-class location when the normalized path is concrete and stable. - If no reliable path is available, keep prior synthetic behaviour by not forcing a concrete location. Effect: - Restores stable receiver-location output for method_accesses while preserving concrete locations when we have trustworthy binary-path information. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/main/kotlin/KotlinUsesExtractor.kt | 7 ++++--- java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt index 22e6ed0a5df..5e1642872eb 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt @@ -1005,9 +1005,10 @@ open class KotlinUsesExtractor( val binaryPath = getContainerSourceBinaryPath(d.containerSource) ?.let { normalizeExternalFileClassBinaryPath(it, fqName) } - ?: "/!unknown-binary-location/${fqName.asString().replace(".", "/")}.class" - val fileId = tw.mkFileId(binaryPath, true) - tw.writeHasLocation(fileClassId, tw.getWholeFileLocation(fileId)) + if (binaryPath != null && shouldUseConcreteExternalFileClassLocation(binaryPath)) { + val fileId = tw.mkFileId(binaryPath, true) + tw.writeHasLocation(fileClassId, tw.getWholeFileLocation(fileId)) + } } return fileClassId } diff --git a/java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt b/java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt index 4027d57e534..7038a2060bb 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt @@ -228,6 +228,12 @@ fun normalizeExternalFileClassBinaryPath(path: String, fqName: FqName): String { return path } +fun shouldUseConcreteExternalFileClassLocation(path: String): Boolean { + val normalizedPath = path.replace('\\', '/') + return normalizedPath.contains("/") && + !normalizedPath.startsWith("/!unknown-binary-location/") +} + fun getJavaEquivalentClassId(c: IrClass) = c.fqNameWhenAvailable?.toUnsafe()?.let { JavaToKotlinClassMap.mapKotlinToJava(it) }