diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index dab1a1e489a..233866e966c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -471,12 +471,17 @@ internal object CheckArguments : CheckerStage() { candidate.symbol.lazyResolveToPhase(FirResolvePhase.STATUS) val argumentMapping = candidate.argumentMapping ?: error("Argument should be already mapped while checking arguments!") - for (argument in callInfo.arguments) { + + val isInvokeFromExtensionFunctionType = candidate.explicitReceiverKind == DISPATCH_RECEIVER + && candidate.dispatchReceiver?.resolvedType?.isExtensionFunctionType == true + && (candidate.symbol as? FirNamedFunctionSymbol)?.name == OperatorNameConventions.INVOKE + + for ((index, argument) in callInfo.arguments.withIndex()) { candidate.resolveArgument( callInfo, argument, argumentMapping[argument], - isReceiver = false, + isReceiver = index == 0 && isInvokeFromExtensionFunctionType, sink = sink, context = context ) diff --git a/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt b/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt index 01e89d765f6..5503cc92820 100644 --- a/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt +++ b/compiler/testData/diagnostics/tests/ExtensionCallInvoke.fir.kt @@ -2,6 +2,6 @@ fun bar(doIt: Int.() -> Int) { 1.doIt() 1?.doIt() val i: Int? = 1 - i.doIt() + i.doIt() i?.doIt() } diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt index 2f9e8397e46..2d462b598b7 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt @@ -77,9 +77,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 48420f026b1..56f6eaaf5a2 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/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt index a25478b8cce..2d47c797732 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.fir.kt @@ -12,7 +12,7 @@ fun test(f: Runnable.(Int) -> Unit, runnable: Runnable) { fun Int.test(f: String.(Int) -> Unit) { f("", 0) - f("") + f("") with("") { f(0) f(0.0) diff --git a/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt deleted file mode 100644 index 1d3e66b699f..00000000000 --- a/compiler/testData/diagnostics/tests/regressions/kt5362.fir.kt +++ /dev/null @@ -1,30 +0,0 @@ -// KT-5362 Compiler crashes on access to extension method from nested class -class Outer { - class Nested{ - fun foo(s: String) = s.extension() - } - - private fun String.extension(): String = this -} - -// EA-64302 - UOE: CodegenContext.getOuterExpression -fun Activity.toast() = Unit -class Activity(){ - class Fragment{ - fun call() = toast() - } -} - -// KT-8814 No error in IDE for invalid invoke of OuterClass.()->Unit in static nested class -public class Manager { - fun task(callback: Manager.() -> Unit): Task { - val task = Task(callback) - return task - } - - class Task(val callback: Manager.() -> Unit) : Runnable { - override public fun run() { - callback() // Manager is not accessible here, but no error is shown - } - } -} diff --git a/compiler/testData/diagnostics/tests/regressions/kt5362.kt b/compiler/testData/diagnostics/tests/regressions/kt5362.kt index 150df91af39..b2635036736 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt5362.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt5362.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // KT-5362 Compiler crashes on access to extension method from nested class class Outer { class Nested{ 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 9b35f1fddd6..2bac50b07f5 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt @@ -1,16 +1,16 @@ 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) { - 11.(f)(1) - 11.(f)() + 11.(f)(1) + 11.(f)() } fun test3() { fun foo(): String.(Int) -> Unit = {} - 1.(foo())(1) + 1.(foo())(1) } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt index 06a139ed434..a449ea3efd2 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt @@ -9,5 +9,5 @@ fun test(identifier: SomeClass, fn: String.() -> Unit) { identifier() identifier(123) identifier(1, 2) - 1.fn() + 1.fn() } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt index 87a1cfc5754..069fda35cf2 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt @@ -16,7 +16,7 @@ fun test(a: A, b: B) { b.(foo)() - (b.foo)() + (b.foo)() foo(b) (foo)(b) diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt index b2dcb167b24..137968d0b37 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.fir.kt @@ -8,5 +8,5 @@ fun test(identifier: SomeClass, fn: String.() -> Unit) { identifier() identifier(123) identifier(1, 2) - 1.fn() + 1.fn() }