mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Replace Map and similar functions with their Java cousins
This didn't appear to be necessary because the Kotlin and Java versions of Map (for example) are designed to be compatible, but in certain cases their functions have the same erasure but not the same type (e.g. Map.getOrDefault(K, V) vs. Map.getOrDefault(Object, V). These have different erasures which was leading to callable-binding inconsistencies.
This commit is contained in:
@@ -899,17 +899,36 @@ open class KotlinUsesExtractor(
|
||||
return id
|
||||
}
|
||||
|
||||
fun kotlinFunctionToJavaEquivalent(f: IrFunction) =
|
||||
f.parent.let {
|
||||
when (it) {
|
||||
is IrClass ->
|
||||
getJavaEquivalentClass(it)?.let { javaClass ->
|
||||
if (javaClass != it)
|
||||
javaClass.declarations.find { decl ->
|
||||
decl is IrFunction && decl.name == f.name && decl.valueParameters.size == f.valueParameters.size
|
||||
} as IrFunction
|
||||
else
|
||||
null
|
||||
}
|
||||
else -> null
|
||||
} ?: f
|
||||
}
|
||||
|
||||
fun <T: DbCallable> useFunction(f: IrFunction, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>? = null): Label<out T> {
|
||||
if (f.isLocalFunction()) {
|
||||
val ids = getLocallyVisibleFunctionLabels(f)
|
||||
return ids.function.cast<T>()
|
||||
} else {
|
||||
return useFunctionCommon<T>(f, getFunctionLabel(f, classTypeArgsIncludingOuterClasses))
|
||||
val realFunction = kotlinFunctionToJavaEquivalent(f)
|
||||
return useFunctionCommon<T>(realFunction, getFunctionLabel(realFunction, classTypeArgsIncludingOuterClasses))
|
||||
}
|
||||
}
|
||||
|
||||
fun <T: DbCallable> useFunction(f: IrFunction, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
|
||||
useFunctionCommon<T>(f, getFunctionLabel(f, parentId, classTypeArgsIncludingOuterClasses))
|
||||
kotlinFunctionToJavaEquivalent(f).let {
|
||||
useFunctionCommon<T>(it, getFunctionLabel(it, parentId, classTypeArgsIncludingOuterClasses))
|
||||
}
|
||||
|
||||
fun getTypeArgumentLabel(
|
||||
arg: IrTypeArgument
|
||||
|
||||
Reference in New Issue
Block a user