Skip to content

Commit b09b769

Browse files
committed
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.
1 parent d291e0c commit b09b769

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,7 @@ open class KotlinFileExtractor(
173173

174174
fun extractTypeParameter(tp: IrTypeParameter, apparentIndex: Int): Label<out DbTypevariable>? {
175175
with("type parameter", tp) {
176-
val parentId: Label<out DbClassorinterfaceorcallable>? = when (val parent = tp.parent) {
177-
is IrFunction -> useFunction(parent)
178-
is IrClass -> useClassSource(parent)
179-
else -> {
180-
logger.errorElement("Unexpected type parameter parent", tp)
181-
null
182-
}
183-
}
184-
185-
if (parentId == null) {
186-
return null
187-
}
188-
176+
val parentId = getTypeParameterParentLabel(tp) ?: return null
189177
val id = tw.getLabelFor<DbTypevariable>(getTypeParameterLabel(tp))
190178

191179
// Note apparentIndex does not necessarily equal `tp.index`, because at least constructor type parameters

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,21 @@ open class KotlinUsesExtractor(
10831083
return classTypeResult.id
10841084
}
10851085

1086+
fun getTypeParameterParentLabel(param: IrTypeParameter) =
1087+
param.parent.let {
1088+
when (it) {
1089+
is IrClass -> useClassSource(it)
1090+
is IrFunction -> useFunction(it, noReplace = true)
1091+
else -> { logger.error("Unexpected type parameter parent $it"); null }
1092+
}
1093+
}
1094+
10861095
fun getTypeParameterLabel(param: IrTypeParameter): String {
1087-
val parentLabel = useDeclarationParent(param.parent, false)
1096+
// Use this instead of `useDeclarationParent` so we can use useFunction with noReplace = true,
1097+
// ensuring that e.g. a method-scoped type variable declared on kotlin.String.transform <R> gets
1098+
// a different name to the corresponding java.lang.String.transform <R>, even though useFunction
1099+
// will usually replace references to one function with the other.
1100+
val parentLabel = getTypeParameterParentLabel(param)
10881101
return "@\"typevar;{$parentLabel};${param.name}\""
10891102
}
10901103

0 commit comments

Comments
 (0)