diff --git a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 5ff6c58e760..b0d10e48996 100644 --- a/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/lightTree/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -448,7 +448,7 @@ class ExpressionsConverter( this.calleeReference = when { name != null -> FirSimpleNamedReference(null, name.nameAsSafeName(), null) additionalArgument != null -> { - arguments += additionalArgument!! + explicitReceiver = additionalArgument!! FirSimpleNamedReference(null, OperatorNameConventions.INVOKE, null) } else -> FirErrorNamedReferenceImpl(null, FirSimpleDiagnostic("Call has no callee", DiagnosticKind.Syntax)) diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 1994ceb08bc..c40753380af 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1242,7 +1242,7 @@ class RawFirBuilder(session: FirSession, val stubMode: Boolean) : BaseFirBuilder null, FirSimpleDiagnostic("Call has no callee", DiagnosticKind.Syntax) ) else -> { - arguments += calleeExpression.toFirExpression("Incorrect invoke receiver") + explicitReceiver = calleeExpression.toFirExpression("Incorrect invoke receiver") FirSimpleNamedReference( source, OperatorNameConventions.INVOKE, null ) diff --git a/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt index 4159c2f1f40..367745fc256 100644 --- a/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt +++ b/compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.txt @@ -30,7 +30,7 @@ FILE: calls.kt } public? final? fun testInvoke(): Int { - ^testInvoke invoke#(My#(Int(13))) + ^testInvoke My#(Int(13)).invoke#() } public? final? fun testQualified(first: My, second: My?): R|kotlin/Unit| { println#(first#.x#) diff --git a/compiler/fir/resolve/testData/resolve/arguments/invoke.kt b/compiler/fir/resolve/testData/resolve/arguments/invoke.kt new file mode 100644 index 00000000000..c9392ab0068 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/invoke.kt @@ -0,0 +1,9 @@ +class My(var x: Int) { + operator fun invoke() = x + + fun foo() {} + + fun copy() = My(x) +} + +fun testInvoke(): Int = My(13)() \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/arguments/invoke.txt b/compiler/fir/resolve/testData/resolve/arguments/invoke.txt new file mode 100644 index 00000000000..d9d773e98be --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/invoke.txt @@ -0,0 +1,25 @@ +FILE: invoke.kt + public final class My : R|kotlin/Any| { + public constructor(x: R|kotlin/Int|): R|My| { + super() + } + + public final var x: R|kotlin/Int| = R|/x| + public get(): R|kotlin/Int| + public set(value: R|kotlin/Int|): R|kotlin/Unit| + + public final operator fun invoke(): R|kotlin/Int| { + ^invoke this@R|/My|.R|/My.x| + } + + public final fun foo(): R|kotlin/Unit| { + } + + public final fun copy(): R|My| { + ^copy R|/My.My|(this@R|/My|.R|/My.x|) + } + + } + public final fun testInvoke(): R|kotlin/Int| { + ^testInvoke R|/My.My|(Int(13)).R|/My.invoke|() + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 827d7185df6..85450449de9 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -230,6 +230,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/arguments/default.kt"); } + @TestMetadata("invoke.kt") + public void testInvoke() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/arguments/invoke.kt"); + } + @TestMetadata("lambda.kt") public void testLambda() throws Exception { runTest("compiler/fir/resolve/testData/resolve/arguments/lambda.kt"); diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt index 3439817dc7b..fefedbc8126 100644 --- a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt @@ -18,11 +18,11 @@ FILE fqName: fileName:/variableAsFunctionCall.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2 (f: kotlin.Function1): IrErrorType declared in ' ERROR_CALL 'Unresolved reference: #' type=IrErrorType - FUN name:test3 visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test3 (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - CALL 'public final fun k (): kotlin.Function0 declared in ' type=kotlin.Function0 origin=null + RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.String declared in ' + CALL 'public abstract fun invoke (): kotlin.String declared in kotlin.Function0' type=kotlin.String origin=null + $this: CALL 'public final fun k (): kotlin.Function0 declared in ' type=kotlin.Function0 origin=null $receiver: CONST String type=kotlin.String value="hello" FUN name:test4 visibility:public modality:FINAL <> (ns:kotlin.String?) returnType:kotlin.String? VALUE_PARAMETER name:ns index:0 type:kotlin.String?