KT-60341 [Analysis API] Provide a type for a FirNameReference only when it refers to an actual property/variable
We cannot always return null, because in such case some expressions would become not fully explorable from the types perspective (see the documentation on the `getCorrespondingTypeIfPossible`) `FirNamedReference` might appear when resolving method references (like `foo::bar`), but also when IJ Platform tries to resolve other parts of the Kotlin PSI, notably a `KtNameReferenceExpression` in a function call (`bar` in `foo.bar(baz)` expression). N.B. FE10 implementation does not support returning `null` as a type - currently it always returns `Unit` type in case it cannot figure out the actual type. This issue should probably be tackled together with KT-60166, so that both implementations are more or less aligned ^KT-60341 Fixed ^KT-59077 Fixed ^KTIJ-25745 Fixed
This commit is contained in:
+8
-5
@@ -34,11 +34,14 @@ abstract class AbstractAnalysisApiExpressionPsiTypeProviderTest : AbstractAnalys
|
||||
?: error("Can't find psi context for $containingDeclaration")
|
||||
val actual = analyze(ktFile) {
|
||||
val returnType = declarationAtCaret.getKtType()
|
||||
?: error("Not a typable expression ${declarationAtCaret::class} ${declarationAtCaret.text}")
|
||||
val psiType = returnType.asPsiType(psiContext, allowErrorTypes = false)
|
||||
buildString {
|
||||
appendLine("KtType: ${returnType.render(position = Variance.INVARIANT)}")
|
||||
appendLine("PsiType: $psiType")
|
||||
if (returnType != null) {
|
||||
val psiType = returnType.asPsiType(psiContext, allowErrorTypes = false)
|
||||
buildString {
|
||||
appendLine("KtType: ${returnType.render(position = Variance.INVARIANT)}")
|
||||
appendLine("PsiType: $psiType")
|
||||
}
|
||||
} else {
|
||||
"null"
|
||||
}
|
||||
}
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
|
||||
Reference in New Issue
Block a user