mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Extract type parameters without substituting their parent functions
Otherwise references to type variables declared on kotlin.Xyz.someFunction can refer to its Java equivalent java.Xyz.someFunction if it has one.
This commit is contained in:
@@ -173,19 +173,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
fun extractTypeParameter(tp: IrTypeParameter, apparentIndex: Int): Label<out DbTypevariable>? {
|
||||
with("type parameter", tp) {
|
||||
val parentId: Label<out DbClassorinterfaceorcallable>? = when (val parent = tp.parent) {
|
||||
is IrFunction -> useFunction(parent)
|
||||
is IrClass -> useClassSource(parent)
|
||||
else -> {
|
||||
logger.errorElement("Unexpected type parameter parent", tp)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
if (parentId == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val parentId = getTypeParameterParentLabel(tp) ?: return null
|
||||
val id = tw.getLabelFor<DbTypevariable>(getTypeParameterLabel(tp))
|
||||
|
||||
// Note apparentIndex does not necessarily equal `tp.index`, because at least constructor type parameters
|
||||
|
||||
@@ -1083,8 +1083,21 @@ open class KotlinUsesExtractor(
|
||||
return classTypeResult.id
|
||||
}
|
||||
|
||||
fun getTypeParameterParentLabel(param: IrTypeParameter) =
|
||||
param.parent.let {
|
||||
when (it) {
|
||||
is IrClass -> useClassSource(it)
|
||||
is IrFunction -> useFunction(it, noReplace = true)
|
||||
else -> { logger.error("Unexpected type parameter parent $it"); null }
|
||||
}
|
||||
}
|
||||
|
||||
fun getTypeParameterLabel(param: IrTypeParameter): String {
|
||||
val parentLabel = useDeclarationParent(param.parent, false)
|
||||
// Use this instead of `useDeclarationParent` so we can use useFunction with noReplace = true,
|
||||
// ensuring that e.g. a method-scoped type variable declared on kotlin.String.transform <R> gets
|
||||
// a different name to the corresponding java.lang.String.transform <R>, even though useFunction
|
||||
// will usually replace references to one function with the other.
|
||||
val parentLabel = getTypeParameterParentLabel(param)
|
||||
return "@\"typevar;{$parentLabel};${param.name}\""
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user