[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:
+7
-4
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user