[Analysis API] KTIJ-24192 Use only lowerBound on flexible types when looking for decompiled PSI

Otherwise, decompiled declarations with flexible types in them cannot be
properly resolved by the Analysis API

Examples of such declarations:

```kt
fun foo()/*: ImplicitTypeFromJava! */ = <some call to java code>

var bar/*: ImplicitTypeFromJava! */ = foo()
// set(value: ImplicitTypeFromJava!) { ... }
```

^KTIJ-24192 Fixed
This commit is contained in:
Roman Golyshev
2023-02-03 23:17:12 +01:00
parent 0608e44b17
commit 08831c0867
@@ -193,13 +193,21 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
}
is ConeTypeVariableType -> lookupTag.name.asString()
is ConeLookupTagBasedType -> lookupTag.name.asString()
// NOTE: Flexible types can occur not only as implicit return types,
// but also as implicit parameter types, for example in setters with implicit types
is ConeFlexibleType -> {
// Can be present as return type
"${lowerBound.renderTypeAsKotlinType()}..${upperBound.renderTypeAsKotlinType()}"
// since Kotlin decompiler always "renders" flexible types as their lower bound, we can do the same here
lowerBound.renderTypeAsKotlinType()
}
else -> errorWithFirSpecificEntries("Type should not be present in Kotlin declaration", coneType = this)
}.replace('/', '.')
return rendered + nullability.suffix
// UNKNOWN nullability occurs only on flexible types
val nullabilitySuffix = nullability.takeUnless { it == ConeNullability.UNKNOWN }?.suffix.orEmpty()
return rendered + nullabilitySuffix
}
private fun ConeTypeProjection.renderTypeAsKotlinType(): String = when (this) {