diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 45c40572c38..0403fac5c76 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -453,8 +453,6 @@ public interface Errors { DiagnosticFactory1 MISSING_RECEIVER = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 NO_RECEIVER_ALLOWED = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 FREE_FUNCTION_CALLED_AS_EXTENSION = DiagnosticFactory0.create(ERROR); - // Call resolution DiagnosticFactory1 ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR); @@ -475,6 +473,7 @@ public interface Errors { DiagnosticFactory1>> NONE_APPLICABLE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 8749f6a7089..f7d56efe498 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -591,13 +591,12 @@ public class DefaultErrorMessages { MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS); MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference: {0}", AMBIGUOUS_CALLS); MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: {0}", AMBIGUOUS_CALLS); + MAP.put(INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION, "Impossible call as extension because {0} is not an extension function.", ELEMENT_TEXT); MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter {0}", NAME); MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE); MAP.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property"); - MAP.put(FREE_FUNCTION_CALLED_AS_EXTENSION, "The function cannot be called as an extension function"); - MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class"); MAP.put(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, "Type inference failed: {0}", TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index 60a95dd2a3d..e1c08420441 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -267,14 +267,18 @@ public class CandidateResolver( } private fun CallCandidateResolutionContext<*>.checkNonExtensionCalledWithReceiver() = checkAndReport { - if (isSynthesizedInvoke(candidateCall.getCandidateDescriptor()) - && !KotlinBuiltIns.isExtensionFunctionType(candidateCall.getDispatchReceiver().getType()) + val call = candidateCall.call + if (call is CallTransformer.CallForImplicitInvoke && candidateCall.extensionReceiver.exists() + && candidateCall.dispatchReceiver.exists() ) { - tracing.freeFunctionCalledAsExtension(trace) - OTHER_ERROR - } else { - SUCCESS + if (call.dispatchReceiver == candidateCall.dispatchReceiver + && !KotlinBuiltIns.isExactExtensionFunctionType(call.dispatchReceiver.type) + ) { + tracing.nonExtensionFunctionCalledAsExtension(trace) + return@checkAndReport OTHER_ERROR + } } + SUCCESS } private fun getReceiverSuper(receiver: ReceiverValue): JetSuperExpression? { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java index 422be54a1ef..e4072d8a711 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java @@ -253,7 +253,7 @@ public abstract class AbstractTracingStrategy implements TracingStrategy { } @Override - public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) { - trace.report(FREE_FUNCTION_CALLED_AS_EXTENSION.on(reference)); + public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) { + trace.report(INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION.on(reference, reference)); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java index f8a5c883b1c..17908e21c6d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java @@ -101,7 +101,7 @@ public interface TracingStrategy { public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData) {} @Override - public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) { } + public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) { } }; void bindCall(@NotNull BindingTrace trace, @NotNull Call call); @@ -153,5 +153,5 @@ public interface TracingStrategy { void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData); - void freeFunctionCalledAsExtension(@NotNull BindingTrace trace); + void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java index c7396e14b5e..28b41074cf8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java @@ -534,7 +534,7 @@ public class ControlStructureTypingUtils { } @Override - public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) { + public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) { logError(); } } diff --git a/compiler/testData/codegen/box/regressions/kt3999.kt b/compiler/testData/codegen/box/regressions/kt3999.kt index 2bbe3215dc3..9cb3283e5e9 100644 --- a/compiler/testData/codegen/box/regressions/kt3999.kt +++ b/compiler/testData/codegen/box/regressions/kt3999.kt @@ -1,16 +1,4 @@ -class A() { - fun A.invoke(a: A) = "$this ${this@A} $a" -} - -fun test1() { - val a = A() - val b = A() - val c = A() - a.b(c) - a b c -} - -fun test2() { +fun test() { val a: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->Unit = {} val b: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->Unit = {"$this $it"} val c: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->Unit = {} @@ -22,8 +10,7 @@ fun Int.foo(a: Int) = this * a val boo = fun Int.(a: Int): Int = this + a fun box(): String { - test1() - test2() + test() 1 foo 2 3 boo 4 return "OK" diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt index e890300076d..2d89ffd77b2 100644 --- a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt +++ b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt @@ -1,5 +1,5 @@ fun foo(a: (String) -> Unit) { - "".a() + "".a() } @@ -9,5 +9,5 @@ interface A : (String) -> Unit {} fun foo(a: @Extension A) { // @Extension annotation on an unrelated type shouldn't have any effect on this diagnostic. // Only kotlin.Function{n} type annotated with @Extension should - "".a() -} + "".a() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.kt b/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.kt index 572060a3510..bb3b9ae4e84 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/functionalBound.kt @@ -1,13 +1,13 @@ fun Unit)?> foo(x: E, y: T) { if (x != null) { - x.y() + x.y() } if (y != null) { - x.y() + x.y() } if (x != null && y != null) { - x.y() + x.y() } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.kt index 0a2521aaf5c..44a8ddc8f32 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/receiverPresenceErrorForInvoke.kt @@ -5,7 +5,7 @@ fun test1(f: String.() -> Unit) { } fun test2(f: (Int) -> Int) { - 1.f(2) + 1.f(2) - 2.(f)(2) -} + 2.(f)(2) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.kt new file mode 100644 index 00000000000..e2cc9ed4bc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.kt @@ -0,0 +1,35 @@ +class B + +class A { + operator fun B.invoke() = 4 +} + +class X { + operator fun invoke() = 3 +} + +fun test(a: A, b: B) { + with (a) { + b() + (b)() + } + + X()() + val x = X() + x() + (x)() +} + +fun test(c: () -> String, e: Int.() -> String) { + c() + (c)() + + 3.e() + 3.(e)() + with(3) { + e() + (e)() + } +} + +fun with(receiver: T, f: T.() -> R): R = receiver.f() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.txt b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.txt new file mode 100644 index 00000000000..8c9b78d2e1d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.txt @@ -0,0 +1,28 @@ +package + +public fun test(/*0*/ c: () -> kotlin.String, /*1*/ e: kotlin.Int.() -> kotlin.String): kotlin.Unit +public fun test(/*0*/ a: A, /*1*/ b: B): kotlin.Unit +public fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public final operator fun B.invoke(): kotlin.Int +} + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class X { + public constructor X() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun invoke(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.kt index eec18dafdb9..3eaa296e07f 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAsMemberExtensionToExplicitReceiver.kt @@ -4,7 +4,7 @@ interface Foo { } fun test(a: A, foo: Foo) { - a.foo() + a.foo() } fun test(a: Int, foo: Int.()->Unit) { diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt new file mode 100644 index 00000000000..5eca683f6fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt @@ -0,0 +1,20 @@ +class B + +class A { + operator fun B.invoke() {} +} + +val B.a: () -> Int get() = { 5 } + +fun test(a: A, b: B) { + val x: Int = b.a() + + b.(a)() + + with(b) { + val y: Int = a() + (a)() + } +} + +fun with(receiver: T, f: T.() -> R): R = receiver.f() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.txt b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.txt new file mode 100644 index 00000000000..d07320ed21f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.txt @@ -0,0 +1,20 @@ +package + +public val B.a: () -> kotlin.Int +public fun test(/*0*/ a: A, /*1*/ b: B): kotlin.Unit +public fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public final operator fun B.invoke(): kotlin.Unit +} + +public final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.kt b/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.kt index 3b7ac8eb1ca..53c75c4c705 100644 --- a/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.kt +++ b/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.kt @@ -1,9 +1,5 @@ -class Foo() { - fun Int.invoke() {} -} - -fun bar(f: Foo, i: Int) { +fun bar(f: Int.() -> Unit, i: Int) { with (i) { f() } -} \ No newline at end of file +} diff --git a/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.txt b/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.txt index ce97e5b63cc..323a7c3e023 100644 --- a/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.txt +++ b/compiler/testData/resolvedCalls/invoke/implicitReceiverForInvoke.txt @@ -1,8 +1,4 @@ -class Foo() { - fun Int.invoke() {} -} - -fun bar(f: Foo, i: Int) { +fun bar(f: Int.() -> Unit, i: Int) { with (i) { f() } @@ -11,8 +7,8 @@ fun bar(f: Foo, i: Int) { Resolved call: -Resulting descriptor: fun Int.invoke(): Unit defined in Foo +Resulting descriptor: operator fun Int.invoke(): Unit defined in kotlin.Function1 Explicit receiver kind = DISPATCH_RECEIVER -Dispatch receiver = f {Foo} +Dispatch receiver = f {[@kotlin.Extension] Function1} Extension receiver = IntExt{fun Int.(): Unit defined in bar} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 0e844f0392e..2b561541b97 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -12815,6 +12815,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("implicitInvoke.kt") + public void testImplicitInvoke() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/implicitInvoke.kt"); + doTest(fileName); + } + @TestMetadata("invokeAsExtension.kt") public void testInvokeAsExtension() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.kt"); @@ -12881,6 +12887,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("wrongInvokeExtension.kt") + public void testWrongInvokeExtension() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/wrongInvokeExtension.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/diagnostics/tests/resolve/invoke/errors") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt b/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt index 59172fa33dd..d7950c9184b 100644 --- a/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt +++ b/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt @@ -1,9 +1,5 @@ class A { - fun test(b: B) { + fun test(b: A.() -> Unit) { this.b() } } - -class B() { - fun A.invoke() {} -} \ No newline at end of file diff --git a/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt.after b/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt.after index 1247c0d7718..12c062e7238 100644 --- a/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt.after +++ b/idea/testData/shortenRefs/this/shortenThisBothReceivers.kt.after @@ -1,9 +1,5 @@ class A { - fun test(b: B) { + fun test(b: A.() -> Unit) { b() } } - -class B() { - fun A.invoke() {} -} \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt b/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt deleted file mode 100644 index 799281857f2..00000000000 --- a/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt +++ /dev/null @@ -1,14 +0,0 @@ -class Bar { - init { - Foo()() - } -} - -class Foo() { - fun Bar.invoke() {} -} - -fun foobar(f: Foo) { - Bar().f() - Bar().f() -} \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt.match b/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt.match deleted file mode 100644 index f68a12d7618..00000000000 --- a/idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt.match +++ /dev/null @@ -1,3 +0,0 @@ -Bar().f() - -Bar().f() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java index 4e0635b7351..063b585defe 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java @@ -365,12 +365,6 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/unifier/equivalence/expressions/calls"), Pattern.compile("^(.+)\\.kt$"), true); } - @TestMetadata("bothReceivers.kt") - public void testBothReceivers() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/bothReceivers.kt"); - doTest(fileName); - } - @TestMetadata("callAndCalleeRuntime.kt") public void testCallAndCalleeRuntime() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/callAndCalleeRuntime.kt"); diff --git a/js/js.translator/testData/expression/invoke/cases/infixCall.kt b/js/js.translator/testData/expression/invoke/cases/infixCall.kt index 5fa7f872f69..0e1bc571b4d 100644 --- a/js/js.translator/testData/expression/invoke/cases/infixCall.kt +++ b/js/js.translator/testData/expression/invoke/cases/infixCall.kt @@ -1,20 +1,7 @@ // KT-3998 Infix call doesn't work for function literals and another classes which implements invoke convention (in JS backend) package foo -class A(val s: String) { - fun A.invoke(a: A) = "${this.s} ${this@A.s} ${a.s}" -} - -fun test1(): String { - val a = A("a") - val b = A("b") - val c = A("c") - val f = a.b(c) // works - val s = a b c //compiler crashes - return "$f | $s" -} - -fun test2(): String { +fun test(): String { val a: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = { "a" } val b: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = { val aa = this as @Extension Function2; @@ -29,8 +16,7 @@ fun test2(): String { } fun box(): String { - assertEquals("a b c | a b c", test1()) - assertEquals("a b c | a b c", test2()) + assertEquals("a b c | a b c", test()) return "OK" } diff --git a/js/js.translator/testData/expression/invoke/cases/inheritFromFunctionTraits.kt b/js/js.translator/testData/expression/invoke/cases/inheritFromFunctionTraits.kt index 32d4d7e9cda..f47ecace2e5 100644 --- a/js/js.translator/testData/expression/invoke/cases/inheritFromFunctionTraits.kt +++ b/js/js.translator/testData/expression/invoke/cases/inheritFromFunctionTraits.kt @@ -4,6 +4,7 @@ * This led to runtime errors (see KT-7692), so the test is temporarily disabled. * * TODO: support inheritance from function types and re-enable this test + * NOTE: inheritance from extension function is forbidden now */ package foo @@ -16,42 +17,24 @@ class Baz/* : Function2*/ { fun invoke(i: Int, b: Boolean) = "Baz.invoke($i, $b)" } -class ExtBar/* : ExtensionFunction0*/ { - fun String.invoke() = "ExtBar.invoke($this)" -} - -class ExtBaz/* : ExtensionFunction2*/ { - fun String.invoke(i: Int, b: Boolean) = "ExtBaz.invoke($this, $i, $b)" -} - class Mixed/* : Function1, - Function2, - ExtensionFunction1, - ExtensionFunction2*/ + Function2*/ { fun invoke(i: Int) = "Mixed.invoke($i)" fun invoke(i: Int, b: Boolean) = "Mixed.invoke($i, $b)" - fun Int.invoke(b: Boolean) = "ext Mixed.invoke($this, $b)" - fun Int.invoke(i: Int, b: Boolean) = "ext Mixed.invoke($this, $i, $b)" } fun box(): String { val bar = Bar() val baz = Baz() - val extBar = ExtBar() - val extBaz = ExtBaz() val mixed = Mixed() assertEquals("Bar.invoke()", bar()) assertEquals("Baz.invoke(2, false)", baz(2, false)) - assertEquals("ExtBar.invoke(2e2)", "2e2".extBar()) - assertEquals("ExtBaz.invoke(29, 34, true)", "29".extBaz(34, true)) assertEquals("Mixed.invoke(45)", mixed(45)) assertEquals("Mixed.invoke(552, true)", mixed(552, true)) - assertEquals("ext Mixed.invoke(21, true)", 21.mixed(true)) - assertEquals("ext Mixed.invoke(29, 304, false)", 29.mixed(304, false)) return "OK" } diff --git a/js/js.translator/testData/expression/invoke/cases/invokeWithDispatchAndExtensionReceivers.kt b/js/js.translator/testData/expression/invoke/cases/invokeWithDispatchAndExtensionReceivers.kt index 03be01a7f3a..7101730d301 100644 --- a/js/js.translator/testData/expression/invoke/cases/invokeWithDispatchAndExtensionReceivers.kt +++ b/js/js.translator/testData/expression/invoke/cases/invokeWithDispatchAndExtensionReceivers.kt @@ -1,12 +1,9 @@ package foo class A -class B { - fun A.invoke(i: Int) = i -} fun box(): Boolean { val a = A() - val b = B() + val b = fun A.(i: Int) = i return a.(b)(1) == 1 }