[FIR] Resolve receiver in qualified expressions with no selector

In qualified expression like `foo().`, selector expression is null.
Because of that the whole expression was marked as an error FIR
expression, and `foo()` part was not resolved at all (including
arguments and everything else).

This commit fixes the problem by providing receiver's FIR expression
as an underlying expression for error FIR expression. That way
it will be seen by all resolve transformers and will be successfully
resolved.

^KTIJ-21484 Fixed
This commit is contained in:
Roman Golyshev
2022-04-11 14:54:17 +04:00
committed by Space
parent 3b53d8694f
commit 32fa2fc476
20 changed files with 169 additions and 20 deletions
@@ -554,10 +554,13 @@ class ExpressionsConverter(
result = convertFirSelector(it, dotQualifiedExpression.toFirSourceElement(), firReceiver!!) as? FirExpression
}
return result ?: buildErrorExpression(
null,
ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax)
)
return result ?: buildErrorExpression {
source = null
diagnostic = ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax)
// if there is no selector, we still want to resolve the receiver
expression = firReceiver
}
}
/**
@@ -2389,14 +2389,19 @@ open class RawFirBuilder(
}
override fun visitQualifiedExpression(expression: KtQualifiedExpression, data: Unit): FirElement {
val receiver = expression.receiverExpression.toFirExpression("Incorrect receiver expression")
val selector = expression.selectorExpression
?: return buildErrorExpression(
expression.toFirSourceElement(), ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax),
)
?: return buildErrorExpression {
source = expression.toFirSourceElement()
diagnostic = ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax)
// if there is no selector, we still want to resolve the receiver
this.expression = receiver
}
val firSelector = selector.toFirExpression("Incorrect selector expression")
if (firSelector is FirQualifiedAccess) {
val receiver = expression.receiverExpression.toFirExpression("Incorrect receiver expression")
if (expression is KtSafeQualifiedExpression) {
@OptIn(FirImplementationDetail::class)
firSelector.replaceSource(expression.toFirSourceElement(KtFakeSourceElementKind.DesugaredSafeCallExpression))