[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:
+5
@@ -2844,6 +2844,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptySelectorInQualifiedExpression.kt")
|
||||
public void testEmptySelectorInQualifiedExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/emptySelectorInQualifiedExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectConstructor.kt")
|
||||
public void testExpectConstructor() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/expectConstructor.kt");
|
||||
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
FILE: emptySelectorInQualifiedExpression.kt
|
||||
public final fun foo(action: R|() -> kotlin/Unit| = fun <anonymous>(): R|kotlin/Unit| <inline=Unknown> {
|
||||
^ Unit
|
||||
}
|
||||
): R|kotlin/Int| {
|
||||
^foo Int(0)
|
||||
}
|
||||
public final fun usageResolved1(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
public final fun usageResolved2(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
public final fun usageResolved3(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
public final fun usageUnresolved1(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
public final fun usageUnresolved2(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
public final fun usageUnresolved3(): R|kotlin/Unit| {
|
||||
ERROR_EXPR(Qualified expression without selector)
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
fun foo(action: () -> Unit = {}): Int = 0
|
||||
|
||||
fun usageResolved1() {
|
||||
foo().<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun usageResolved2() {
|
||||
foo()?.<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun usageResolved3() {
|
||||
foo {
|
||||
foo()
|
||||
}.<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun usageUnresolved1() {
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>().<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun usageUnresolved2() {
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()?.<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun usageUnresolved3() {
|
||||
foo {
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}.<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
+6
@@ -3225,6 +3225,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("emptySelectorInQualifiedExpression.kt")
|
||||
public void testEmptySelectorInQualifiedExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/emptySelectorInQualifiedExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectConstructor.kt")
|
||||
public void testExpectConstructor() throws Exception {
|
||||
|
||||
+6
@@ -3225,6 +3225,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("emptySelectorInQualifiedExpression.kt")
|
||||
public void testEmptySelectorInQualifiedExpression() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/emptySelectorInQualifiedExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectConstructor.kt")
|
||||
public void testExpectConstructor() throws Exception {
|
||||
|
||||
+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