Skip to content

Commit ab89146

Browse files
committed
Kotlin: Don't convert back and forth between ClassId and FqName
This showed up as a bug in Kotlin 2 mode: We were starting with the Class Id "java/util/Map.Entry", which we then converted to the FqName "java.util.Map.Entry", and then back to a Class Id with ClassId.topLevel. This gave us a Class Id that referenceClass wasn't able to resolve. Now we just stick with the Class Id that we started with, and the class can be resolved by Kotlin 2.
1 parent ed9502f commit ab89146

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ open class KotlinUsesExtractor(
139139
}
140140

141141
fun getJavaEquivalentClass(c: IrClass) =
142-
getJavaEquivalentClassId(c)?.let { getClassByFqName(pluginContext, it.asSingleFqName()) }?.owner
142+
getJavaEquivalentClassId(c)?.let { getClassByClassId(pluginContext, it) }?.owner
143143

144144
/**
145145
* Gets a KotlinFileExtractor based on this one, except it attributes locations to the file that declares the given class.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/ReferenceEntity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package com.github.codeql.utils
22

33
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
44
import org.jetbrains.kotlin.ir.symbols.*
5+
import org.jetbrains.kotlin.name.ClassId
56
import org.jetbrains.kotlin.name.FqName
67
import org.jetbrains.kotlin.name.Name
78

89
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
910
return pluginContext.referenceClass(fqName)
1011
}
1112

13+
fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? {
14+
return getClassByFqName(pluginContext, id.asSingleFqName())
15+
}
16+
1217
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
1318
val fqName = pkgName.child(name)
1419
return pluginContext.referenceFunctions(fqName)

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/ReferenceEntity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import org.jetbrains.kotlin.name.Name
1010

1111
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
1212
val id = ClassId.topLevel(fqName)
13+
return getClassByClassId(pluginContext, id)
14+
}
15+
16+
fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? {
1317
return pluginContext.referenceClass(id)
1418
}
1519

0 commit comments

Comments
 (0)