diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 07db4abeaf2..5a6ea238210 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -551,6 +551,7 @@ class ExpressionsConverter( } } + var result = firSelector (firSelector as? FirQualifiedAccess)?.let { if (isSafe) { @OptIn(FirImplementationDetail::class) @@ -561,13 +562,10 @@ class ExpressionsConverter( ) } - it.replaceExplicitReceiver(firReceiver) - - @OptIn(FirImplementationDetail::class) - it.replaceSource(dotQualifiedExpression.toFirSourceElement()) + result = convertFirSelector(it, dotQualifiedExpression.toFirSourceElement(), firReceiver!!) as? FirExpression } - return firSelector ?: buildErrorExpression( + return result ?: buildErrorExpression( null, ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax) ) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index b2b7bb903c5..17f0785c411 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -2374,10 +2374,7 @@ open class RawFirBuilder( ) } - firSelector.replaceExplicitReceiver(receiver) - - @OptIn(FirImplementationDetail::class) - firSelector.replaceSource(expression.toFirSourceElement()) + return convertFirSelector(firSelector, expression.toFirSourceElement(), receiver) } return firSelector } diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index eabe8a7c0f6..056468b50dc 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -1266,6 +1266,31 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } } + protected fun convertFirSelector( + firSelector: FirQualifiedAccess, + source: KtSourceElement?, + receiver: FirExpression + ): FirQualifiedAccess { + return if (firSelector is FirImplicitInvokeCall) { + buildImplicitInvokeCall { + this.source = source + annotations.addAll(firSelector.annotations) + typeArguments.addAll(firSelector.typeArguments) + explicitReceiver = firSelector.explicitReceiver + argumentList = buildArgumentList { + arguments.add(receiver) + arguments.addAll(firSelector.arguments) + } + calleeReference = firSelector.calleeReference + } + } else { + firSelector.replaceExplicitReceiver(receiver) + @OptIn(FirImplementationDetail::class) + firSelector.replaceSource(source) + firSelector + } + } + protected fun convertValueParameterName( safeName: Name, rawName: String?, diff --git a/compiler/testData/codegen/box/extensionFunctions/executionOrder.kt b/compiler/testData/codegen/box/extensionFunctions/executionOrder.kt index 2db5cb1b9e7..38cdf5f0d5b 100644 --- a/compiler/testData/codegen/box/extensionFunctions/executionOrder.kt +++ b/compiler/testData/codegen/box/extensionFunctions/executionOrder.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: UNRESOLVED_REFERENCE at getFun. Questionable syntax var result = "" fun getReceiver() : Int { diff --git a/compiler/testData/codegen/box/functions/functionExpression/functionExpression.kt b/compiler/testData/codegen/box/functions/functionExpression/functionExpression.kt index 026e696c498..0936de3f951 100644 --- a/compiler/testData/codegen/box/functions/functionExpression/functionExpression.kt +++ b/compiler/testData/codegen/box/functions/functionExpression/functionExpression.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: FUNCTION_EXPECTED after 1. . Questionable syntax val foo1 = fun Any.(): String { return "239" + this } diff --git a/compiler/testData/codegen/box/functions/functionExpression/functionLiteralExpression.kt b/compiler/testData/codegen/box/functions/functionExpression/functionLiteralExpression.kt index 51ddd912db9..5ee7f510702 100644 --- a/compiler/testData/codegen/box/functions/functionExpression/functionLiteralExpression.kt +++ b/compiler/testData/codegen/box/functions/functionExpression/functionLiteralExpression.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: FUNCTION_EXPECTED after 1. . Questionable syntax fun Any.foo1() : ()-> String { return { "239" + this } } diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt index f4770d6dbd7..abc8ebf2126 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt @@ -58,15 +58,15 @@ fun main(args : Array) { fun f() : Int.() -> Unit = {} fun main1() { - 1.(fun Int.() = 1)(); + 1.(fun Int.() = 1)(); {1}(); (fun (x : Int) = x)(1) - 1.(fun Int.(x : Int) = x)(1); + 1.(fun Int.(x : Int) = x)(1); l@{1}() - 1.((fun Int.() = 1))() - 1.(f())() - 1.if(true){f()}else{f()}() - 1.if(true)(fun Int.() {})else{f()}() + 1.((fun Int.() = 1))() + 1.(f())() + 1.if(true){f()}else{f()}() + 1.if(true)(fun Int.() {})else{f()}() 1."sdf"() @@ -78,9 +78,9 @@ fun main1() { fun test() { {x : Int -> 1}(); (fun Int.() = 1)() - "sd".(fun Int.() = 1)() + "sd".(fun Int.() = 1)() val i : Int? = null - i.(fun Int.() = 1)(); + i.(fun Int.() = 1)(); {}() 1?.(fun Int.() = 1)() 1.{}() diff --git a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt index 62c2c7b2367..d783d6241f4 100644 --- a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt +++ b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.fir.kt @@ -34,7 +34,7 @@ fun test4() { // should be an error on receiver, shouldn't be thrown away fun test5() { - 1.(fun String.()=1)() + 1.(fun String.()=1)() } fun R?.sure() : R = this!! diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt index eca0df8fc6e..7ff5eb86954 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt @@ -1,7 +1,7 @@ fun test1() { - 1. (fun String.(i: Int) = i )(1) - 1.(label@ fun String.(i: Int) = i )(1) + 1. (fun String.(i: Int) = i )(1) + 1.(label@ fun String.(i: Int) = i )(1) } fun test2(f: String.(Int) -> Unit) { @@ -12,5 +12,5 @@ fun test2(f: String.(Int) -> Unit) { fun test3() { fun foo(): String.(Int) -> Unit = {} - 1.(foo())(1) + 1.(foo())(1) } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt index 9edb90f6966..3d84cac8b12 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.fir.kt @@ -2,11 +2,11 @@ class A(val x: (String.() -> Unit)?) fun test(a: A) { if (a.x != null) { - "".(a.x)() + "".(a.x)() a.x("") // todo (a.x)("") } - "".(a.x)() + "".(a.x)() a.x("") (a.x)("") diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt index 6a32eb70ba4..3497ac9552f 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt @@ -7,7 +7,7 @@ class B val A.foo: B.() -> Unit get() = {} fun test(a: A, b: B) { - b.(a.foo)() + b.(a.foo)() (a.foo)(b) a.foo(b) @@ -49,7 +49,7 @@ class A { class B fun test(a: A, b: B) { - b.(a.foo)() + b.(a.foo)() (a.foo)(b) a.foo(b)