mirror of
https://github.com/github/codeql.git
synced 2026-06-29 16:47:09 +02:00
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user