Fix raw FIR building with parenthesized expression as selector
This commit is contained in:
+21
-9
@@ -440,17 +440,29 @@ class ExpressionsConverter(
|
||||
val valueArguments = mutableListOf<LighterASTNode>()
|
||||
var additionalArgument: FirExpression? = null
|
||||
var hasArguments = false
|
||||
callSuffix.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
REFERENCE_EXPRESSION -> name = it.asText
|
||||
TYPE_ARGUMENT_LIST -> firTypeArguments += declarationsConverter.convertTypeArguments(it)
|
||||
VALUE_ARGUMENT_LIST, LAMBDA_ARGUMENT -> {
|
||||
hasArguments = true
|
||||
valueArguments += it
|
||||
callSuffix.forEachChildren { child ->
|
||||
fun process(node: LighterASTNode) {
|
||||
when (node.tokenType) {
|
||||
REFERENCE_EXPRESSION -> {
|
||||
name = node.asText
|
||||
}
|
||||
PARENTHESIZED -> node.getExpressionInParentheses()?.let { process(it) } ?: run {
|
||||
additionalArgument = getAsFirExpression(node, "Incorrect invoke receiver")
|
||||
}
|
||||
TYPE_ARGUMENT_LIST -> {
|
||||
firTypeArguments += declarationsConverter.convertTypeArguments(node)
|
||||
}
|
||||
VALUE_ARGUMENT_LIST, LAMBDA_ARGUMENT -> {
|
||||
hasArguments = true
|
||||
valueArguments += node
|
||||
}
|
||||
else -> if (node.tokenType != TokenType.ERROR_ELEMENT) {
|
||||
additionalArgument = getAsFirExpression(node, "Incorrect invoke receiver")
|
||||
}
|
||||
}
|
||||
else -> if (it.tokenType != TokenType.ERROR_ELEMENT) additionalArgument =
|
||||
getAsFirExpression(it, "Incorrect invoke receiver")
|
||||
}
|
||||
|
||||
process(child)
|
||||
}
|
||||
|
||||
val (calleeReference, explicitReceiver) = when {
|
||||
|
||||
+5
@@ -213,6 +213,11 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("init.kt")
|
||||
public void testInit() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.fir.impl.FirLabelImpl
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -1253,23 +1254,29 @@ class RawFirBuilder(session: FirSession, val stubMode: Boolean) : BaseFirBuilder
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: KtCallExpression, data: Unit): FirElement {
|
||||
val calleeExpression = expression.calleeExpression
|
||||
val source = expression.toFirSourceElement()
|
||||
|
||||
val (calleeReference, explicitReceiver) = when (calleeExpression) {
|
||||
private fun splitToCalleeAndReceiver(
|
||||
calleeExpression: KtExpression?,
|
||||
defaultSource: FirPsiSourceElement
|
||||
): Pair<FirNamedReference, FirExpression?> {
|
||||
return when (calleeExpression) {
|
||||
is KtSimpleNameExpression -> FirSimpleNamedReference(
|
||||
calleeExpression.toFirSourceElement(), calleeExpression.getReferencedNameAsName(), null
|
||||
) to null
|
||||
is KtParenthesizedExpression -> splitToCalleeAndReceiver(calleeExpression.expression, defaultSource)
|
||||
null -> FirErrorNamedReferenceImpl(
|
||||
null, FirSimpleDiagnostic("Call has no callee", DiagnosticKind.Syntax)
|
||||
) to null
|
||||
else -> {
|
||||
FirSimpleNamedReference(
|
||||
source, OperatorNameConventions.INVOKE, null
|
||||
defaultSource, OperatorNameConventions.INVOKE, null
|
||||
) to calleeExpression.toFirExpression("Incorrect invoke receiver")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: KtCallExpression, data: Unit): FirElement {
|
||||
val source = expression.toFirSourceElement()
|
||||
val (calleeReference, explicitReceiver) = splitToCalleeAndReceiver(expression.calleeExpression, source)
|
||||
|
||||
val result = if (expression.valueArgumentList == null && expression.lambdaArguments.isEmpty()) {
|
||||
FirQualifiedAccessExpressionImpl(source).apply {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test(e: Int.() -> String) {
|
||||
val s = 3.e()
|
||||
val ss = 3.(e)()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
FILE: inBrackets.kt
|
||||
public? final? fun test(e: ( Int.() -> String )): R|kotlin/Unit| {
|
||||
lval s: <implicit> = IntegerLiteral(3).e#()
|
||||
lval ss: <implicit> = IntegerLiteral(3).e#()
|
||||
}
|
||||
Generated
+5
@@ -213,6 +213,11 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("init.kt")
|
||||
public void testInit() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
fun test(e: Int.() -> String) {
|
||||
val s = 3.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
val ss = 3.(<!UNRESOLVED_REFERENCE!>e<!>)()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
FILE: inBrackets.kt
|
||||
public final fun test(e: R|kotlin/Int.() -> kotlin/String|): R|kotlin/Unit| {
|
||||
lval s: <ERROR TYPE REF: Unresolved name: e> = Int(3).<Unresolved name: e>#()
|
||||
lval ss: <ERROR TYPE REF: Unresolved name: e> = Int(3).<Unresolved name: e>#()
|
||||
}
|
||||
+5
@@ -679,6 +679,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/implicitTypeOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyFromParameter.kt")
|
||||
public void testPropertyFromParameter() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyFromParameter.kt");
|
||||
|
||||
Generated
+5
@@ -679,6 +679,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/implicitTypeOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyFromParameter.kt")
|
||||
public void testPropertyFromParameter() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyFromParameter.kt");
|
||||
|
||||
Vendored
+1
-1
@@ -45,7 +45,7 @@ fun test() {
|
||||
x4 checkType { <!UNRESOLVED_REFERENCE!>_<!><Function1<Int, Unit>>() }
|
||||
|
||||
{ y: Int -> fun named14(): Int {return 1} }
|
||||
val b = <!UNRESOLVED_REFERENCE!><!INFERENCE_ERROR!>(fun named15(): Boolean { return true })<!>()<!>
|
||||
val b = <!UNRESOLVED_REFERENCE!>(<!INFERENCE_ERROR!>fun named15(): Boolean { return true }<!>)()<!>
|
||||
|
||||
baz(<!INFERENCE_ERROR!>fun named16(){}<!>)
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ enum class E {
|
||||
val foo: Any.() -> Unit = {}
|
||||
|
||||
fun f1() = E.FIRST.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
fun f2() = E.FIRST.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
fun f2() = E.FIRST.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
fun f3() = E.SECOND.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
fun f4() = E.SECOND.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
fun f4() = E.SECOND.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
fun f5() = E.SECOND.A()
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ enum class E {
|
||||
val foo: Any.() -> Unit = {}
|
||||
|
||||
fun f1() = E.FIRST.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
fun f2() = E.FIRST.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
fun f2() = E.FIRST.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
fun f3() = E.SECOND.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
fun f4() = E.SECOND.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
fun f4() = E.SECOND.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
fun f5() = E.SECOND.A()
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
fun test1(f: String.() -> Unit) {
|
||||
<!INAPPLICABLE_CANDIDATE!>(f)()<!>
|
||||
(<!INAPPLICABLE_CANDIDATE!>f<!>)()
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>f<!>()
|
||||
}
|
||||
@@ -7,5 +7,5 @@ fun test1(f: String.() -> Unit) {
|
||||
fun test2(f: (Int) -> Int) {
|
||||
1.<!UNRESOLVED_REFERENCE!>f<!>(2)
|
||||
|
||||
2.<!UNRESOLVED_REFERENCE!>(f)(2)<!>
|
||||
2.(<!UNRESOLVED_REFERENCE!>f<!>)(2)
|
||||
}
|
||||
Vendored
+2
-2
@@ -6,8 +6,8 @@ fun test1() {
|
||||
}
|
||||
|
||||
fun test2(f: String.(Int) -> Unit) {
|
||||
11.<!UNRESOLVED_REFERENCE!>(f)(1)<!>
|
||||
11.<!UNRESOLVED_REFERENCE!>(f)()<!>
|
||||
11.(<!UNRESOLVED_REFERENCE!>f<!>)(1)
|
||||
11.(<!UNRESOLVED_REFERENCE!>f<!>)()
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
|
||||
@@ -25,9 +25,9 @@ fun test(c: () -> String, e: Int.() -> String) {
|
||||
(c)()
|
||||
|
||||
3.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
3.<!UNRESOLVED_REFERENCE!>(e)()<!>
|
||||
3.(<!UNRESOLVED_REFERENCE!>e<!>)()
|
||||
with(3) {
|
||||
<!INAPPLICABLE_CANDIDATE!>e<!>()
|
||||
<!INAPPLICABLE_CANDIDATE!>(e)()<!>
|
||||
(<!INAPPLICABLE_CANDIDATE!>e<!>)()
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+6
-6
@@ -15,7 +15,7 @@ fun test(a: A, b: B) {
|
||||
with(a) {
|
||||
b.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
|
||||
b.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
b.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
|
||||
<!UNRESOLVED_REFERENCE!>(b.<!INAPPLICABLE_CANDIDATE!>foo<!>)()<!>
|
||||
|
||||
@@ -25,7 +25,7 @@ fun test(a: A, b: B) {
|
||||
|
||||
with(b) {
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
a.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
a.(<!INAPPLICABLE_CANDIDATE!>foo<!>)()
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>(a.foo)()<!>
|
||||
|
||||
@@ -36,7 +36,7 @@ fun test(a: A, b: B) {
|
||||
with(a) {
|
||||
with(b) {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
<!INAPPLICABLE_CANDIDATE!>(foo)()<!>
|
||||
(<!INAPPLICABLE_CANDIDATE!>foo<!>)()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ fun test(a: A, b: B) {
|
||||
with(a) {
|
||||
b.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
|
||||
b.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
b.(<!UNRESOLVED_REFERENCE!>foo<!>)()
|
||||
|
||||
<!UNRESOLVED_REFERENCE!>(b.<!UNRESOLVED_REFERENCE!>foo<!>)()<!>
|
||||
|
||||
@@ -67,7 +67,7 @@ fun test(a: A, b: B) {
|
||||
|
||||
with(b) {
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
a.<!UNRESOLVED_REFERENCE!>(foo)()<!>
|
||||
a.(<!INAPPLICABLE_CANDIDATE!>foo<!>)()
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>(a.foo)()<!>
|
||||
|
||||
@@ -78,7 +78,7 @@ fun test(a: A, b: B) {
|
||||
with(a) {
|
||||
with(b) {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
<!INAPPLICABLE_CANDIDATE!>(foo)()<!>
|
||||
(<!INAPPLICABLE_CANDIDATE!>foo<!>)()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,10 +9,10 @@ val B.a: () -> Int get() = { 5 }
|
||||
fun test(a: A, b: B) {
|
||||
val x: Int = b.a()
|
||||
|
||||
b.<!UNRESOLVED_REFERENCE!>(a)()<!>
|
||||
b.(a)()
|
||||
|
||||
with(b) {
|
||||
val y: Int = <!UNRESOLVED_REFERENCE!>a<!>()
|
||||
<!UNRESOLVED_REFERENCE!>(a)()<!>
|
||||
(<!UNRESOLVED_REFERENCE!>a<!>)()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// FIR_IGNORE
|
||||
fun test(e: Int.() -> String) {
|
||||
// String
|
||||
// │ Int
|
||||
// │ │ fun Int.invoke(): String
|
||||
// │ │ │
|
||||
val s = 3.e()
|
||||
// String
|
||||
// │ Int
|
||||
// │ │ fun Int.invoke(): String
|
||||
// │ │ │test.e: Int.() -> String
|
||||
// │ │ ││
|
||||
val ss = 3.(e)()
|
||||
}
|
||||
+5
@@ -213,6 +213,11 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizer {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("init.kt")
|
||||
public void testInit() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
|
||||
|
||||
+5
@@ -213,6 +213,11 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizer {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inBrackets.kt")
|
||||
public void testInBrackets() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/inBrackets.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("init.kt")
|
||||
public void testInit() throws Exception {
|
||||
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
|
||||
|
||||
Reference in New Issue
Block a user