Skip to content

Commit b82ec0e

Browse files
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>
1 parent bc2d710 commit b82ec0e

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,10 @@ open class KotlinUsesExtractor(
10051005
val binaryPath =
10061006
getContainerSourceBinaryPath(d.containerSource)
10071007
?.let { normalizeExternalFileClassBinaryPath(it, fqName) }
1008-
?: "/!unknown-binary-location/${fqName.asString().replace(".", "/")}.class"
1009-
val fileId = tw.mkFileId(binaryPath, true)
1010-
tw.writeHasLocation(fileClassId, tw.getWholeFileLocation(fileId))
1008+
if (binaryPath != null && shouldUseConcreteExternalFileClassLocation(binaryPath)) {
1009+
val fileId = tw.mkFileId(binaryPath, true)
1010+
tw.writeHasLocation(fileClassId, tw.getWholeFileLocation(fileId))
1011+
}
10111012
}
10121013
return fileClassId
10131014
}

java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ fun normalizeExternalFileClassBinaryPath(path: String, fqName: FqName): String {
228228
return path
229229
}
230230

231+
fun shouldUseConcreteExternalFileClassLocation(path: String): Boolean {
232+
val normalizedPath = path.replace('\\', '/')
233+
return normalizedPath.contains("/") &&
234+
!normalizedPath.startsWith("/!unknown-binary-location/")
235+
}
236+
231237
fun getJavaEquivalentClassId(c: IrClass) =
232238
c.fqNameWhenAvailable?.toUnsafe()?.let { JavaToKotlinClassMap.mapKotlinToJava(it) }
233239

0 commit comments

Comments
 (0)