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:
Roman Golyshev
2023-06-03 00:21:17 +02:00
committed by teamcity
parent 19a60d6b85
commit b8052761db
66 changed files with 870 additions and 30 deletions
@@ -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)