Skip to content

Commit 3195404

Browse files
authored
Merge pull request #10272 from igfoo/igfoo/getDeclaringTypeArguments
Kotlin: Remove some casts from getDeclaringTypeArguments
2 parents 07b3b15 + 6a4b748 commit 3195404

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,16 +1336,25 @@ open class KotlinFileExtractor(
13361336
}
13371337

13381338
// If a path was found, repeatedly substitute types to get the corresponding specialisation of that ancestor.
1339-
return if (!walkFrom(receiverClass)) {
1339+
if (!walkFrom(receiverClass)) {
13401340
logger.errorElement("Failed to find a class declaring ${callTarget.name} starting at ${receiverClass.name}", callTarget)
1341-
listOf()
1341+
return listOf()
13421342
} else {
1343-
var subbedType = receiverType
1343+
var subbedType: IrSimpleType = receiverType
13441344
ancestorTypes.forEach {
13451345
val thisClass = subbedType.classifier.owner as IrClass
1346-
subbedType = it.substituteTypeArguments(thisClass.typeParameters, subbedType.arguments) as IrSimpleType
1346+
if (thisClass !is IrClass) {
1347+
logger.errorElement("Found ancestor with unexpected type ${thisClass.javaClass}", callTarget)
1348+
return listOf()
1349+
}
1350+
val itSubbed = it.substituteTypeArguments(thisClass.typeParameters, subbedType.arguments)
1351+
if (itSubbed !is IrSimpleType) {
1352+
logger.errorElement("Substituted type has unexpected type ${itSubbed.javaClass}", callTarget)
1353+
return listOf()
1354+
}
1355+
subbedType = itSubbed
13471356
}
1348-
subbedType.arguments
1357+
return subbedType.arguments
13491358
}
13501359
}
13511360

0 commit comments

Comments
 (0)