diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 9c3d1163253..b9f6c7a80d9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -225,53 +225,35 @@ public class ClosureCodegen extends MemberCodegen { @NotNull public StackValue putInstanceOnStack(@NotNull final ExpressionCodegen codegen) { - return StackValue.operation(asmType, new Function1() { - @Override - public Unit invoke(InstructionAdapter v) { - if (isConst(closure)) { - v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor()); - } - else { - v.anew(asmType); - v.dup(); + return StackValue.operation( + functionReferenceTarget != null ? K_FUNCTION : asmType, + new Function1() { + @Override + public Unit invoke(InstructionAdapter v) { + if (isConst(closure)) { + v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor()); + } + else { + v.anew(asmType); + v.dup(); - codegen.pushClosureOnStack(classDescriptor, true, codegen.defaultCallGenerator); - v.invokespecial(asmType.getInternalName(), "", constructor.getDescriptor(), false); - } + codegen.pushClosureOnStack(classDescriptor, true, codegen.defaultCallGenerator); + v.invokespecial(asmType.getInternalName(), "", constructor.getDescriptor(), false); + } - if (functionReferenceTarget != null) { - equipFunctionReferenceWithReflection(v, functionReferenceTarget); - } + if (functionReferenceTarget != null) { + v.invokestatic(REFLECTION, "function", Type.getMethodDescriptor(K_FUNCTION, FUNCTION_REFERENCE), false); + } - return Unit.INSTANCE$; - } - }); + return Unit.INSTANCE$; + } + } + ); } - private static void equipFunctionReferenceWithReflection(@NotNull InstructionAdapter v, @NotNull FunctionDescriptor target) { - DeclarationDescriptor container = target.getContainingDeclaration(); - - Type type; - if (container instanceof PackageFragmentDescriptor) { - type = target.getExtensionReceiverParameter() != null - ? K_TOP_LEVEL_EXTENSION_FUNCTION - : K_TOP_LEVEL_FUNCTION; - } - else if (container instanceof ClassDescriptor) { - type = K_MEMBER_FUNCTION; - } - else { - type = K_LOCAL_FUNCTION; - } - - Method method = method("function", K_FUNCTION, FUNCTION_REFERENCE); - v.invokestatic(REFLECTION, method.getName(), method.getDescriptor(), false); - StackValue.coerce(K_FUNCTION, type, v); - } - - private void generateConstInstance() { - MethodVisitor mv = v.newMethod(OtherOrigin(element, funDescriptor), ACC_STATIC | ACC_SYNTHETIC, "", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY); + MethodVisitor mv = v.newMethod(OtherOrigin(element, funDescriptor), ACC_STATIC | ACC_SYNTHETIC, "", "()V", null, + ArrayUtil.EMPTY_STRING_ARRAY); InstructionAdapter iv = new InstructionAdapter(mv); v.newField(OtherOrigin(element, funDescriptor), ACC_STATIC | ACC_FINAL | ACC_PUBLIC, JvmAbi.INSTANCE_FIELD, asmType.getDescriptor(), diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java index 92a9f33c3a6..9ea0bc24122 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.codegen; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.codegen.state.GenerationState; @@ -133,8 +134,14 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat } private void computeAndSaveArguments(@NotNull List fakeArguments, @NotNull ExpressionCodegen codegen) { - for (ValueParameterDescriptor parameter : callableDescriptor.getValueParameters()) { - ValueArgument fakeArgument = fakeArguments.get(parameter.getIndex()); + int receivers = (referencedFunction.getDispatchReceiverParameter() != null ? 1 : 0) + + (referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0); + + List parameters = KotlinPackage.drop(callableDescriptor.getValueParameters(), receivers); + for (int i = 0; i < parameters.size(); i++) { + ValueParameterDescriptor parameter = parameters.get(i); + ValueArgument fakeArgument = fakeArguments.get(i); + Type type = state.getTypeMapper().mapType(parameter); int localIndex = codegen.myFrameMap.getIndex(parameter); codegen.tempVariables.put(fakeArgument.getArgumentExpression(), StackValue.local(localIndex, type)); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java index f174878ca74..fc1cdc5a981 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java @@ -43,10 +43,6 @@ public class AsmTypes { public static final Type K_DECLARATION_CONTAINER_TYPE = reflect("KDeclarationContainer"); public static final Type K_FUNCTION = reflect("KFunction"); - public static final Type K_TOP_LEVEL_FUNCTION = reflect("KTopLevelFunction"); - public static final Type K_MEMBER_FUNCTION = reflect("KMemberFunction"); - public static final Type K_TOP_LEVEL_EXTENSION_FUNCTION = reflect("KTopLevelExtensionFunction"); - public static final Type K_LOCAL_FUNCTION = reflect("KLocalFunction"); public static final Type K_MEMBER_PROPERTY_TYPE = reflect("KMemberProperty"); public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = reflect("KMutableMemberProperty"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index e177156ba62..dce191599b6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -704,7 +704,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { boolean isExtension = extensionReceiver != null; if (descriptor instanceof FunctionDescriptor) { - return createFunctionReferenceType(expression, context, (FunctionDescriptor) descriptor, receiverType, isExtension); + return createFunctionReferenceType(expression, context, (FunctionDescriptor) descriptor, receiverType); } else if (descriptor instanceof PropertyDescriptor) { return createPropertyReferenceType(expression, context, (PropertyDescriptor) descriptor, receiverType, isExtension); @@ -722,16 +722,14 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { @NotNull JetCallableReferenceExpression expression, @NotNull ExpressionTypingContext context, @NotNull FunctionDescriptor descriptor, - @Nullable JetType receiverType, - boolean isExtension + @Nullable JetType receiverType ) { //noinspection ConstantConditions JetType type = components.reflectionTypes.getKFunctionType( Annotations.EMPTY, receiverType, getValueParametersTypes(descriptor.getValueParameters()), - descriptor.getReturnType(), - isExtension + descriptor.getReturnType() ); AnonymousFunctionDescriptor functionDescriptor = new AnonymousFunctionDescriptor( diff --git a/compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/J.java b/compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/J.java index 6536c732dea..100310e99de 100644 --- a/compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/J.java +++ b/compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/J.java @@ -1,9 +1,9 @@ import kotlin.jvm.functions.Function2; -import kotlin.reflect.KMemberFunction; +import kotlin.reflect.KFunction; public class J { public static String go() { - KMemberFunction fun = K.Companion.getRef(); + KFunction fun = K.Companion.getRef(); Object result = ((Function2) fun).invoke(new K(), "KO"); return (String) result; } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/abstractClassMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/abstractClassMember.kt index a5718485bec..515b25914d0 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/abstractClassMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/abstractClassMember.kt @@ -6,4 +6,4 @@ class B : A() { override fun foo() = "OK" } -fun box(): String = B().(A::foo)() +fun box(): String = (A::foo)(B()) diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/booleanNotIntrinsic.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/booleanNotIntrinsic.kt index 114e328afef..213c8d88996 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/booleanNotIntrinsic.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/booleanNotIntrinsic.kt @@ -1,5 +1,5 @@ fun box(): String { - if (true.(Boolean::not)() != false) return "Fail 1" - if (false.(Boolean::not)() != true) return "Fail 2" + if ((Boolean::not)(true) != false) return "Fail 1" + if ((Boolean::not)(false) != true) return "Fail 2" return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromClass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromClass.kt index 1ef4255bbe1..7f5fd04017f 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromClass.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromClass.kt @@ -1,7 +1,7 @@ class A { fun foo(k: Int) = k - fun result() = this.(::foo)(111) + fun result() = (::foo)(this, 111) } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromExtension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromExtension.kt index f19e87f864c..607fa3700f5 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromExtension.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromExtension.kt @@ -3,7 +3,7 @@ class A { fun k(k: Int) = k } -fun A.foo() = this.(::o)() + this.(A::k)(222) +fun A.foo() = (::o)(this) + (A::k)(this, 222) fun box(): String { val result = A().foo() diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringNoArgs.kt index d7fe34551ef..4ea10740594 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringNoArgs.kt @@ -4,5 +4,5 @@ class A { fun box(): String { val x = A::foo - return A().x() + return x(A()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringOneStringArg.kt index 9e03ba90c63..acdf2f897d5 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelStringOneStringArg.kt @@ -4,5 +4,5 @@ class A { fun box(): String { val x = A::foo - return A().x("OK") + return x(A(), "OK") } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitNoArgs.kt index 4fb93fc926f..37ebbdb72eb 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitNoArgs.kt @@ -9,6 +9,6 @@ class A { fun box(): String { val a = A() val x = A::foo - a.x() + x(a) return a.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt index c982e914210..3b280c28f34 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/classMemberFromTopLevelUnitOneStringArg.kt @@ -9,6 +9,6 @@ class A { fun box(): String { val a = A() val x = A::foo - a.x("OK") + x(a, "OK") return a.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/enumNameMethod.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/enumNameMethod.kt index 1aa7fc633b2..b6a1bf51558 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/enumNameMethod.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/enumNameMethod.kt @@ -3,7 +3,7 @@ enum class E { } fun box(): String { - val i = E.I.(E::name)() + val i = (E::name)(E.I) if (i != "I") return "Fail $i" return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/equalsIntrinsic.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/equalsIntrinsic.kt index be58579704b..c83a188802d 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/equalsIntrinsic.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/equalsIntrinsic.kt @@ -1,3 +1,3 @@ class A -fun box() = if (A().(A::equals)(A())) "Fail" else "OK" +fun box() = if ((A::equals)(A(), A())) "Fail" else "OK" diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromClass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromClass.kt index 0bbfc45d383..f5dabed6746 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromClass.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromClass.kt @@ -1,5 +1,5 @@ class A { - fun result() = this.(::foo)("OK") + fun result() = (::foo)(this, "OK") } fun A.foo(x: String) = x diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromExtension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromExtension.kt index 4f43bb608d8..103ceee5cbc 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromExtension.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromExtension.kt @@ -1,6 +1,6 @@ class A -fun A.foo() = this.(A::bar)("OK") +fun A.foo() = (A::bar)(this, "OK") fun A.bar(x: String) = x diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringNoArgs.kt index 46f1caa4528..b5fd42ad9c6 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringNoArgs.kt @@ -4,5 +4,5 @@ fun A.foo() = "OK" fun box(): String { val x = A::foo - return A().x() + return x(A()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringOneStringArg.kt index 9f371dbf329..69db0311a69 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelStringOneStringArg.kt @@ -4,5 +4,5 @@ fun A.foo(result: String) = result fun box(): String { val x = A::foo - return A().x("OK") + return x(A(), "OK") } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitNoArgs.kt index d90c6c98d28..b590ad2ec91 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitNoArgs.kt @@ -9,6 +9,6 @@ fun A.foo() { fun box(): String { val a = A() val x = A::foo - a.x() + x(a) return a.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitOneStringArg.kt index 68fdd0903e5..aa9d5505bbf 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/extensionFromTopLevelUnitOneStringArg.kt @@ -9,6 +9,6 @@ fun A.foo(newResult: String) { fun box(): String { val a = A() val x = A::foo - a.x("OK") + x(a, "OK") return a.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/genericMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/genericMember.kt index 8608c508dde..25dabc055f2 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/genericMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/genericMember.kt @@ -2,4 +2,4 @@ class A(val t: T) { fun foo(): T = t } -fun box() = A("OK").(A::foo)() +fun box() = (A::foo)(A("OK")) diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromClass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromClass.kt index 8f19b83cb4f..53b31fa77d0 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromClass.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromClass.kt @@ -4,7 +4,7 @@ class A { val k = 222 } - fun result() = this.(A::Inner)().o + this.(::Inner)().k + fun result() = (A::Inner)(this).o + (::Inner)(this).k } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromExtension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromExtension.kt index 6fa9653c833..aad8cb2a97a 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromExtension.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromExtension.kt @@ -5,7 +5,7 @@ class A { } } -fun A.foo() = this.(A::Inner)().o + this.(::Inner)().k +fun A.foo() = (A::Inner)(this).o + (::Inner)(this).k fun box(): String { val result = A().foo() diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelNoArgs.kt index b974ba82993..577eb19e7af 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelNoArgs.kt @@ -6,7 +6,7 @@ class A { } fun box(): String { - val result = (::A)().(A::Inner)().o + A().(A::Inner)().k + val result = (A::Inner)((::A)()).o + (A::Inner)(A()).k if (result != 333) return "Fail $result" return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt index e47bd741210..0eb2b831a2b 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/innerConstructorFromTopLevelOneStringArg.kt @@ -3,7 +3,7 @@ class A { } fun box(): String { - val result = (::A)().(A::Inner)(111).result + A().(A::Inner)(222).result + val result = (A::Inner)((::A)(), 111).result + (A::Inner)(A(), 222).result if (result != 333) return "Fail $result" return "OK" } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/captureOuter.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/captureOuter.kt index 46bec43ff91..e653f8f0574 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/captureOuter.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/captureOuter.kt @@ -8,5 +8,5 @@ class Outer { fun box(): String { val f = Outer.Inner::foo - return Outer().Inner().f() + return f(Outer().Inner()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/classMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/classMember.kt index 343e9015c84..72bb8af6e81 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/classMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/classMember.kt @@ -4,5 +4,5 @@ fun box(): String { } val ref = Local::foo - return Local().ref() + return ref(Local()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/enumExtendsTrait.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/enumExtendsTrait.kt index 5b28434e19c..f2bfced60f4 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/enumExtendsTrait.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/enumExtendsTrait.kt @@ -7,5 +7,5 @@ enum class E : Named { } fun box(): String { - return E.OK.(Named::name)() + return (Named::name)(E.OK) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extension.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extension.kt index c0ce1217d94..3919a320e81 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extension.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extension.kt @@ -2,5 +2,5 @@ class A fun box(): String { fun A.foo() = "OK" - return A().(A::foo)() + return (A::foo)(A()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToLocalClass.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToLocalClass.kt index 781d8096ea0..43537f177e9 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToLocalClass.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToLocalClass.kt @@ -1,5 +1,5 @@ fun box(): String { class A fun A.foo() = "OK" - return (::A)().(A::foo)() + return (A::foo)((::A)()) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToPrimitive.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToPrimitive.kt index f8db384261a..9cb84f4df07 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToPrimitive.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionToPrimitive.kt @@ -1,4 +1,4 @@ fun box(): String { fun Int.is42With(that: Int) = this + 2 * that == 42 - return if (16.(Int::is42With)(13)) "OK" else "Fail" + return if ((Int::is42With)(16, 13)) "OK" else "Fail" } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionWithClosure.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionWithClosure.kt index a3e02eef8de..cbbbcd219b1 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionWithClosure.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/extensionWithClosure.kt @@ -6,6 +6,6 @@ fun box(): String { fun A.ext() { result = "OK" } val f = A::ext - A().f() + f(A()) return result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/genericMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/genericMember.kt index ad0db326cd9..12e60f50480 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/genericMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/genericMember.kt @@ -4,5 +4,5 @@ fun box(): String { } val ref = Id::invoke - return Id().ref("OK") + return ref(Id(), "OK") } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/localClassMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/localClassMember.kt index abe1c70a0bd..98f62fb5b40 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/localClassMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/local/localClassMember.kt @@ -7,5 +7,5 @@ fun box(): String { val member = Local::foo val instance = Local() - return instance.member() + return member(instance) } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitNoArgs.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitNoArgs.kt index 35d45d87c65..15191f36579 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitNoArgs.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitNoArgs.kt @@ -8,6 +8,6 @@ object A { fun box(): String { val x = A::foo - A.x() + x(A) return A.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitOneStringArg.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitOneStringArg.kt index 1598361da6a..fe7f8a41b7f 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitOneStringArg.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitOneStringArg.kt @@ -8,6 +8,6 @@ object A { fun box(): String { val x = A::foo - A.x("OK") + x(A, "OK") return A.result } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/privateClassMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/privateClassMember.kt index 1b7ffe85906..c796995fc67 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/privateClassMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/privateClassMember.kt @@ -1,7 +1,7 @@ class A { private fun foo() = "OK" - fun bar() = this.(::foo)() + fun bar() = (::foo)(this) } fun box() = A().bar() diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitImplMethodWithClassReceiver.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitImplMethodWithClassReceiver.kt index b47561d9d03..51923a24746 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitImplMethodWithClassReceiver.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitImplMethodWithClassReceiver.kt @@ -4,7 +4,7 @@ interface T { class B : T { inner class C { - fun bar() = this@B.(::foo)() + fun bar() = (::foo)(this@B) } } diff --git a/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitMember.kt b/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitMember.kt index 619220ff65f..88cf738eaa7 100644 --- a/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitMember.kt +++ b/compiler/testData/codegen/boxWithStdlib/callableReference/function/traitMember.kt @@ -6,4 +6,4 @@ class B : A { override fun foo() = "OK" } -fun box() = B().(A::foo)() +fun box() = (A::foo)(B()) diff --git a/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt b/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt index a0f350cafc5..a02509760fb 100644 --- a/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt +++ b/compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt @@ -28,15 +28,15 @@ object A { } fun box(): String { - if (A.(A::test1)() != "OK") return "fail 1" + if ((A::test1)(A) != "OK") return "fail 1" - if (A.(A::test2)() != "OK") return "fail 2" + if ((A::test2)(A) != "OK") return "fail 2" - if (A.(A::test3)() != "1OK") return "fail 3" + if ((A::test3)(A) != "1OK") return "fail 3" - if (A.(A::test4)() != "1OK") return "fail 4" + if ((A::test4)(A) != "1OK") return "fail 4" if (((A::c).get(A)) != "OK") return "fail 5" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt b/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt index 1a4f2bf1324..dd9fd0af1bd 100644 --- a/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt +++ b/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt @@ -3,8 +3,8 @@ class Z{ fun a(s: Int) {} fun b() { - Z().(Z::a)(1) + (Z::a)(Z(), 1) } } -// 1 invoke \(LZ;I\)V \ No newline at end of file +// 1 invoke \(LZ;I\)V diff --git a/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.kt b/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.kt index 6e62db4637a..76c0a667973 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.kt @@ -5,5 +5,5 @@ open class A { } fun test() { - A.B.(A::foo)() -} \ No newline at end of file + (A::foo)(A.B) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.kt index 593a279e949..1d0c327455f 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageClass.kt @@ -22,7 +22,7 @@ fun main() { val y = first.A::bar val z = A::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.kt index 96b8072ed12..6b26e8a0b3b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/differentPackageExtension.kt @@ -14,7 +14,7 @@ fun A.baz() {} package other -import kotlin.reflect.KExtensionFunction0 +import kotlin.reflect.KFunction1 import first.A import first.foo @@ -24,5 +24,5 @@ fun main() { first.A::bar A::baz - checkSubtype>(x) -} \ No newline at end of file + checkSubtype>(x) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromClass.kt index 7429eb453e2..273919e3ed7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromClass.kt @@ -8,9 +8,9 @@ class A { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtension.kt index a6d251a97ed..7c7a7ea2b2b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtension.kt @@ -9,9 +9,9 @@ fun A.main() { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } fun A.foo() {} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtensionInClass.kt index b45cfba2230..b0b4893a4c7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromExtensionInClass.kt @@ -10,9 +10,9 @@ class A { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.kt index f19de82cb9a..3d69d34d670 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionFromTopLevel.kt @@ -13,11 +13,11 @@ fun main() { val y = A::bar val z = A::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.kt index aa4f0ba464a..5434e7241ab 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.kt @@ -8,5 +8,5 @@ class A { fun A?.foo() {} -val f: KMemberFunction0 = A::foo -val g: KExtensionFunction0 = A?::foo +val f: KFunction1 = A::foo +val g: KFunction1 = A?::foo diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.txt b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.txt index 4fc98ce4243..7db185b8dcc 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.txt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionOnNullable.txt @@ -1,7 +1,7 @@ package -internal val f: kotlin.reflect.KMemberFunction0 -internal val g: kotlin.reflect.KExtensionFunction0 +internal val f: kotlin.reflect.KFunction1 +internal val g: kotlin.reflect.KFunction1 internal fun A?.foo(): kotlin.Unit internal final class A { diff --git a/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.kt index 17447b9cc58..4127983d232 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/genericClassFromTopLevel.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 class A(val t: T) { fun foo(): T = t @@ -9,5 +9,5 @@ class A(val t: T) { fun bar() { val x = A::foo - checkSubtype, String>>(x) + checkSubtype, String>>(x) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt index 8d1a6dce2eb..62e6ab9194d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 class A { inner class Inner @@ -9,8 +9,8 @@ class A { val x = ::Inner val y = A::Inner - checkSubtype>(x) - checkSubtype>(y) + checkSubtype>(x) + checkSubtype>(y) } companion object { @@ -18,7 +18,7 @@ class A { ::Inner val y = A::Inner - checkSubtype>(y) + checkSubtype>(y) } } } @@ -28,6 +28,6 @@ class B { ::Inner val y = A::Inner - checkSubtype>(y) + checkSubtype>(y) } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt index c89325b538e..b23bcdf370d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 class A { inner class Inner @@ -10,13 +10,13 @@ fun A.main() { val x = ::Inner val y = A::Inner - checkSubtype>(x) - checkSubtype>(y) + checkSubtype>(x) + checkSubtype>(y) } fun Int.main() { ::Inner val y = A::Inner - checkSubtype>(y) -} \ No newline at end of file + checkSubtype>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.kt index ad744c2c321..b606d6dbd27 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromTopLevel.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 class A { inner class Inner @@ -10,5 +10,5 @@ fun main() { ::Inner val y = A::Inner - checkSubtype>(y) -} \ No newline at end of file + checkSubtype>(y) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.kt b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.kt index bade88299a3..143296f288d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedName.kt @@ -9,10 +9,10 @@ class D { // FILE: b.kt -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 fun main() { val x = a.b.c.D::foo - checkSubtype>(x) + checkSubtype>(x) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.kt b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.kt index 4fdbc8db48a..755f7118aee 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/longQualifiedNameGeneric.kt @@ -9,10 +9,10 @@ class D { // FILE: b.kt -import kotlin.reflect.KMemberFunction2 +import kotlin.reflect.KFunction3 fun main() { val x = a.b.c.D::foo - checkSubtype, String, Int, a.b.c.D>>(x) + checkSubtype, String, Int, a.b.c.D>>(x) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/memberFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/memberFromClass.kt index da7cdb14875..908e073857b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/memberFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/memberFromClass.kt @@ -12,8 +12,8 @@ class A { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtension.kt index 307e5edcdd2..045edb34120 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtension.kt @@ -13,7 +13,7 @@ fun A.main() { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtensionInClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtensionInClass.kt index 90b04455703..5789a95e8af 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtensionInClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/memberFromExtensionInClass.kt @@ -14,8 +14,8 @@ class B { val y = ::bar val z = ::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.kt index 4a5a9399be4..68705bf7cbf 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/memberFromTopLevel.kt @@ -13,11 +13,11 @@ fun main() { val y = A::bar val z = A::baz - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) - checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(x) + checkSubtype>(y) + checkSubtype>(z) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.kt index 773833fcc44..f8cbe71c6b2 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsExtension.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 class A { fun foo() = 42 @@ -11,5 +11,5 @@ fun A.foo() {} fun main() { val x = A::foo - checkSubtype>(x) + checkSubtype>(x) } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt index 542a48f4ffa..6424f6c7f19 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt @@ -1,6 +1,6 @@ // !CHECK_TYPE -import kotlin.reflect.KMemberFunction0 +import kotlin.reflect.KFunction1 fun foo() {} @@ -10,6 +10,6 @@ class A { fun main() { val x = ::foo - checkSubtype>(x) + checkSubtype>(x) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.kt b/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.kt index 287fe53908a..0d7c73d8a06 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/renameOnImport.kt @@ -25,6 +25,6 @@ fun main() { val z = AA::bazbaz checkSubtype>(x) - checkSubtype>(y) - checkSubtype>(z) + checkSubtype>(y) + checkSubtype>(z) } diff --git a/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt b/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt index 1a6a2ce718b..23441709f8e 100644 --- a/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt +++ b/compiler/testData/diagnostics/tests/deprecated/functionUsage.txt @@ -5,7 +5,7 @@ internal fun block(): kotlin.Unit internal fun expression(): UsefulClass internal fun invoker(): kotlin.Unit internal fun reflection(): kotlin.reflect.KFunction1 -internal fun reflection2(): kotlin.reflect.KMemberFunction0 +internal fun reflection2(): kotlin.reflect.KFunction1 kotlin.deprecated(value = "does nothing good") internal fun kotlin.Any.doNothing(): kotlin.String internal final class Delegation { diff --git a/core/builtins/src/kotlin/reflect/KExtensionFunction.kt b/core/builtins/src/kotlin/reflect/KExtensionFunction.kt deleted file mode 100644 index d2b861e14e7..00000000000 --- a/core/builtins/src/kotlin/reflect/KExtensionFunction.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect - -/** - * Represents an extension function. - * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/extensions.html#extension-functions) - * for more information. - * - * @param E the type of the extension receiver. - * @param R the return type of the function. - */ -public interface KExtensionFunction : KFunction diff --git a/core/builtins/src/kotlin/reflect/KLocalFunction.kt b/core/builtins/src/kotlin/reflect/KLocalFunction.kt deleted file mode 100644 index 31a9aae20ee..00000000000 --- a/core/builtins/src/kotlin/reflect/KLocalFunction.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect - -/** - * Represents a local function. - * - * @param R the return type of the function. - */ -public interface KLocalFunction : KFunction diff --git a/core/builtins/src/kotlin/reflect/KMemberFunction.kt b/core/builtins/src/kotlin/reflect/KMemberFunction.kt deleted file mode 100644 index 70a1c36faef..00000000000 --- a/core/builtins/src/kotlin/reflect/KMemberFunction.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect - -/** - * Represents a member function. - * - * @param T the type of the instance which should be used to call the function. - * Must be derived either from a class declaring this function, or any subclass of that class. - * @param R the return type of the function. - */ -public interface KMemberFunction : KFunction diff --git a/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt b/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt deleted file mode 100644 index 133b1bb61d8..00000000000 --- a/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect - -/** - * Represents an extension function declared in a package. - * - * @param E the type of the extension receiver. - * @param R the return type of the function. - */ -public interface KTopLevelExtensionFunction : KExtensionFunction diff --git a/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt b/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt deleted file mode 100644 index 2f0d18f09bf..00000000000 --- a/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect - -/** - * Represents a function declared in a package. - */ -public interface KTopLevelFunction : KFunction diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/platform/JavaToKotlinClassMap.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/platform/JavaToKotlinClassMap.java index fee5cb32198..f60e27cb0e5 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/platform/JavaToKotlinClassMap.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/platform/JavaToKotlinClassMap.java @@ -80,10 +80,9 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap { for (int i = 0; i < 23; i++) { add(ClassId.topLevel(new FqName("kotlin.jvm.functions.Function" + i)), builtIns.getFunction(i)); - for (FunctionClassDescriptor.Kind kind : FunctionClassDescriptor.Kinds.KFunctions) { - String kFun = kind.getPackageFqName() + "." + kind.getClassNamePrefix(); - addKotlinToJava(new FqNameUnsafe(kFun + i), ClassId.topLevel(new FqName(kFun))); - } + FunctionClassDescriptor.Kind kFunction = FunctionClassDescriptor.Kind.KFunction; + String kFun = kFunction.getPackageFqName() + "." + kFunction.getClassNamePrefix(); + addKotlinToJava(new FqNameUnsafe(kFun + i), ClassId.topLevel(new FqName(kFun))); } addJavaToKotlin(classId(Deprecated.class), builtIns.getDeprecatedAnnotation()); diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt index c3e81262a4c..71539e305b8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/ReflectionTypes.kt @@ -48,8 +48,6 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { } public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n") - public fun getKExtensionFunction(n: Int): ClassDescriptor = find("KExtensionFunction$n") - public fun getKMemberFunction(n: Int): ClassDescriptor = find("KMemberFunction$n") public val kClass: ClassDescriptor by ClassLookup public val kTopLevelVariable: ClassDescriptor by ClassLookup @@ -73,20 +71,16 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { annotations: Annotations, receiverType: JetType?, parameterTypes: List, - returnType: JetType, - extensionFunction: Boolean + returnType: JetType ): JetType { - val arity = parameterTypes.size() - val classDescriptor = - if (extensionFunction) getKExtensionFunction(arity) - else if (receiverType != null) getKMemberFunction(arity) - else getKFunction(arity) + val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType) + + val classDescriptor = getKFunction(arguments.size() - 1 /* return type */) if (ErrorUtils.isError(classDescriptor)) { return classDescriptor.getDefaultType() } - val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType) return JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/BuiltInFictitiousFunctionClassFactory.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/BuiltInFictitiousFunctionClassFactory.kt index 14208047b9e..be111eb74b8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/BuiltInFictitiousFunctionClassFactory.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/BuiltInFictitiousFunctionClassFactory.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.storage.StorageManager import kotlin.platform.platformStatic /** - * Produces descriptors representing the fictitious classes for function types, such as kotlin.Function1 or kotlin.reflect.KMemberFunction0. + * Produces descriptors representing the fictitious classes for function types, such as kotlin.Function1 or kotlin.reflect.KFunction2. */ public class BuiltInFictitiousFunctionClassFactory( private val storageManager: StorageManager, @@ -37,17 +37,15 @@ public class BuiltInFictitiousFunctionClassFactory( companion object { platformStatic public fun parseClassName(className: String, packageFqName: FqName): KindWithArity? { - for (kind in FunctionClassDescriptor.Kinds.byPackage(packageFqName)) { - val prefix = kind.classNamePrefix - if (!className.startsWith(prefix)) continue + val kind = FunctionClassDescriptor.Kind.byPackage(packageFqName) ?: return null - val arity = toInt(className.substring(prefix.length())) ?: continue + val prefix = kind.classNamePrefix + if (!className.startsWith(prefix)) return null - // TODO: validate arity, should be <= 255 for functions, <= 254 for members/extensions - return KindWithArity(kind, arity) - } + val arity = toInt(className.substring(prefix.length())) ?: return null - return null + // TODO: validate arity, should be <= 255 + return KindWithArity(kind, arity) } private fun toInt(s: String): Int? { @@ -70,8 +68,7 @@ public class BuiltInFictitiousFunctionClassFactory( if ("Function" !in className) return null // An optimization val packageFqName = classId.getPackageFqName() - val kindWithArity = parseClassName(className, packageFqName) ?: return null - val (kind, arity) = kindWithArity // KT-5100 + val (kind, arity) = parseClassName(className, packageFqName) ?: return null val containingPackageFragment = module.getPackage(packageFqName).fragments.single() diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt index 8708c36cdac..9ca51bc7e48 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt @@ -17,12 +17,10 @@ package org.jetbrains.kotlin.builtins.functions import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor.Kind import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.name.FqName @@ -32,18 +30,14 @@ import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.utils.toReadOnlyList import java.util.ArrayList -import java.util.EnumSet /** - * A [ClassDescriptor] representing the fictitious class for a function type, such as kotlin.Function1 or kotlin.reflect.KMemberFunction0. + * A [ClassDescriptor] representing the fictitious class for a function type, such as kotlin.Function1 or kotlin.reflect.KFunction2. * - * Classes which are represented by this descriptor include (with supertypes): + * If the class represents kotlin.Function1, its only supertype is kotlin.Function. * - * Function1 : Function - * KFunction1 : Function1, KFunction - * KMemberFunction1 : Function2, KMemberFunction - * KExtensionFunction1 : Function2, KExtensionFunction - * (TODO) KMemberExtensionFunction1 : Function3, KMemberExtensionFunction + * If the class represents kotlin.reflect.KFunction1, it has two supertypes: kotlin.Function1 and kotlin.reflect.KFunction. + * This allows to use both 'invoke' and reflection API on function references obtained by '::'. */ public class FunctionClassDescriptor( private val storageManager: StorageManager, @@ -54,24 +48,16 @@ public class FunctionClassDescriptor( public enum class Kind(val packageFqName: FqName, val classNamePrefix: String) { Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"), - KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction"), - KMemberFunction(KOTLIN_REFLECT_FQ_NAME, "KMemberFunction"), - KExtensionFunction(KOTLIN_REFLECT_FQ_NAME, "KExtensionFunction"); - // TODO: KMemberExtensionFunction + KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction"); fun numberedClassName(arity: Int) = Name.identifier("$classNamePrefix$arity") - val hasDispatchReceiver: Boolean get() = this == KMemberFunction - val hasExtensionReceiver: Boolean get() = this == KExtensionFunction - } - public object Kinds { - val Functions = EnumSet.of(Kind.Function) - val KFunctions = EnumSet.complementOf(Functions) - - fun byPackage(fqName: FqName) = when (fqName) { - BUILT_INS_PACKAGE_FQ_NAME -> Functions - KOTLIN_REFLECT_FQ_NAME -> KFunctions - else -> error(fqName) + companion object { + fun byPackage(fqName: FqName) = when (fqName) { + BUILT_INS_PACKAGE_FQ_NAME -> Function + KOTLIN_REFLECT_FQ_NAME -> KFunction + else -> null + } } } @@ -110,13 +96,6 @@ public class FunctionClassDescriptor( )) } - if (functionKind.hasDispatchReceiver) { - typeParameter(Variance.IN_VARIANCE, "T") - } - if (functionKind.hasExtensionReceiver) { - typeParameter(Variance.IN_VARIANCE, "E") - } - (1..arity).map { i -> typeParameter(Variance.IN_VARIANCE, "P$i") } @@ -129,48 +108,29 @@ public class FunctionClassDescriptor( private val supertypes = storageManager.createLazyValue { val result = ArrayList(2) - fun add( - packageFragment: PackageFragmentDescriptor, - name: Name, - annotations: Annotations, - supertypeArguments: (superParameters: List) -> List - ) { + fun add(packageFragment: PackageFragmentDescriptor, name: Name) { val descriptor = packageFragment.getMemberScope().getClassifier(name) as? ClassDescriptor ?: error("Class $name not found in $packageFragment") val typeConstructor = descriptor.getTypeConstructor() - val arguments = supertypeArguments(typeConstructor.getParameters()) - result.add(JetTypeImpl(annotations, typeConstructor, false, arguments, descriptor.getMemberScope(arguments))) + // Substitute all type parameters of the super class with our last type parameters + val arguments = getParameters().takeLast(typeConstructor.getParameters().size()).map { + TypeProjectionImpl(it.getDefaultType()) + } + + result.add(JetTypeImpl(Annotations.EMPTY, typeConstructor, false, arguments, descriptor.getMemberScope(arguments))) } - // Add unnumbered base class, e.g. KMemberFunction for KMemberFunction5, or Function for Function0 - add(containingDeclaration, Name.identifier(functionKind.classNamePrefix), Annotations.EMPTY) { superParameters -> - // Substitute type parameters of the super class with our type parameters with the same names - val parametersByName = getParameters().toMap { it.getName() } - superParameters.map { TypeProjectionImpl(parametersByName[it.getName()]!!.getDefaultType()) } - } - - // For K*Functions, add corresponding numbered Function class, e.g. Function2 for KMemberFunction1 - if (functionKind in Kinds.KFunctions) { - var functionArity = arity - if (functionKind.hasDispatchReceiver) functionArity++ - if (functionKind.hasExtensionReceiver) functionArity++ + // Add unnumbered base class, e.g. Function for Function{n}, KFunction for KFunction{n} + add(containingDeclaration, Name.identifier(functionKind.classNamePrefix)) + // For KFunction{n}, add corresponding numbered Function{n} class, e.g. Function2 for KFunction2 + if (functionKind == Kind.KFunction) { val module = containingDeclaration.getContainingDeclaration() val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME).fragments.single() - // If this is a KMemberFunction{n} or KExtensionFunction{n}, it extends Function{n} with the annotation kotlin.extension, - // so that the value of this type is callable as an extension function, with the receiver before the dot - val annotations = - if (functionKind.hasDispatchReceiver || functionKind.hasExtensionReceiver) - AnnotationsImpl(listOf(KotlinBuiltIns.getInstance().createExtensionAnnotation())) - else Annotations.EMPTY - - add(kotlinPackageFragment, Kind.Function.numberedClassName(functionArity), annotations) { - // Substitute all type parameters of the super class with all our type parameters - getParameters().map { TypeProjectionImpl(it.getDefaultType()) } - } + add(kotlinPackageFragment, Kind.Function.numberedClassName(arity)) } result.toReadOnlyList() diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt new file mode 100644 index 00000000000..ede7ae70e58 --- /dev/null +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionFromReferenceImpl.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect.jvm.internal + +import org.jetbrains.kotlin.resolve.scopes.JetScope +import kotlin.jvm.internal.FunctionReference +import kotlin.reflect.KotlinReflectionInternalError + +class KFunctionFromReferenceImpl( + val reference: FunctionReference +): KFunctionImpl( + reference.getOwner() as? KCallableContainerImpl ?: EmptyContainerForLocal, + reference.getName(), + reference.getSignature() +) { + override fun getArity() = reference.getArity() + + override val name = reference.getName() + + // The rest of the class is auto-generated. Use the following script: + // (0..22).forEach { n -> println("override fun invoke(" + (1..n).joinToString { "p$it: Any?" } + "): Any? = reference(" + (1..n).joinToString { "p$it" } + ")") } + override fun invoke(): Any? = reference() + override fun invoke(p1: Any?): Any? = reference(p1) + override fun invoke(p1: Any?, p2: Any?): Any? = reference(p1, p2) + override fun invoke(p1: Any?, p2: Any?, p3: Any?): Any? = reference(p1, p2, p3) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?): Any? = reference(p1, p2, p3, p4) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?): Any? = reference(p1, p2, p3, p4, p5) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?): Any? = reference(p1, p2, p3, p4, p5, p6) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?, p20: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?, p20: Any?, p21: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21) + override fun invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?, p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?, p20: Any?, p21: Any?, p22: Any?): Any? = reference(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22) +} + +object EmptyContainerForLocal : KCallableContainerImpl() { + override val jClass: Class<*> + get() = fail() + + override val scope: JetScope + get() = fail() + + private fun fail() = throw KotlinReflectionInternalError("Introspecting local functions is not yet supported in Kotlin reflection") +} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt index 7304bbb3239..69d3ad41ad9 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KFunctionImpl.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import kotlin.jvm.internal.FunctionImpl import kotlin.reflect.KFunction -abstract class KFunctionImpl private constructor( +open class KFunctionImpl protected constructor( container: KCallableContainerImpl, name: String, signature: String, diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java index 6aab0752308..239a77fa24e 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -44,7 +44,7 @@ public class ReflectionFactoryImpl extends ReflectionFactory { @Override public KFunction function(FunctionReference f) { - return new KTopLevelFreeFunctionImpl((KPackageImpl) f.getOwner(), f.getName(), f.getSignature()); + return new KFunctionFromReferenceImpl(f); } // Properties diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kFunctionImplementations.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kFunctionImplementations.kt deleted file mode 100644 index bafd1a4f11f..00000000000 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kFunctionImplementations.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect.jvm.internal - -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import kotlin.reflect.KTopLevelFunction - -class KTopLevelFreeFunctionImpl : KFunctionImpl, KTopLevelFunction { - constructor(container: KPackageImpl, name: String, signature: String): super(container, name, signature) - - constructor(container: KPackageImpl, descriptor: FunctionDescriptor): super(container, descriptor) -} diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/FunctionReference.java b/core/runtime.jvm/src/kotlin/jvm/internal/FunctionReference.java index 2503e3da797..8b7511305d7 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/FunctionReference.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/FunctionReference.java @@ -17,14 +17,10 @@ package kotlin.jvm.internal; import kotlin.jvm.KotlinReflectionNotSupportedError; -import kotlin.reflect.*; +import kotlin.reflect.KDeclarationContainer; +import kotlin.reflect.KFunction; -public class FunctionReference - extends FunctionImpl - implements KTopLevelFunction, - KMemberFunction, - KTopLevelExtensionFunction, - KLocalFunction { +public class FunctionReference extends FunctionImpl implements KFunction { private final int arity; public FunctionReference(int arity) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/FunctionCallableReferenceTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/FunctionCallableReferenceTest.java index 60efbcdfdb0..efc5855e43c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/FunctionCallableReferenceTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/FunctionCallableReferenceTest.java @@ -122,7 +122,7 @@ public final class FunctionCallableReferenceTest extends AbstractCallableReferen checkFooBoxIsOk(); } - public void testClassMemberAndExtensionCompatibility() throws Exception { + public void testClassMemberAndNonExtensionCompatibility() throws Exception { checkFooBoxIsOk(); } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt index 78fc93659fc..0261621774c 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt @@ -173,9 +173,7 @@ object InvokeIntrinsic : FunctionCallCase { funDeclaration == callableDescriptor.builtIns.getFunction(parameterCount) || funDeclaration == reflectionTypes.getKFunction(parameterCount) else - funDeclaration == callableDescriptor.builtIns.getExtensionFunction(parameterCount) || - funDeclaration == reflectionTypes.getKExtensionFunction(parameterCount) || - funDeclaration == reflectionTypes.getKMemberFunction(parameterCount) + funDeclaration == callableDescriptor.builtIns.getExtensionFunction(parameterCount) } override fun FunctionCallInfo.dispatchReceiver(): JsExpression { diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/Namer.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/Namer.java index 0128e3a84f2..b547e8a96bc 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/Namer.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/Namer.java @@ -17,8 +17,8 @@ package org.jetbrains.kotlin.js.translate.context; import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.metadata.TypeCheck; import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage; +import com.google.dart.compiler.backend.js.ast.metadata.TypeCheck; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; @@ -71,6 +71,7 @@ public final class Namer { private static final String OBJECT_OBJECT_NAME = "createObject"; private static final String CALLABLE_REF_FOR_MEMBER_FUNCTION_NAME = "getCallableRefForMemberFunction"; private static final String CALLABLE_REF_FOR_EXTENSION_FUNCTION_NAME = "getCallableRefForExtensionFunction"; + private static final String CALLABLE_REF_FOR_LOCAL_EXTENSION_FUNCTION_NAME = "getCallableRefForLocalExtensionFunction"; private static final String CALLABLE_REF_FOR_CONSTRUCTOR_NAME = "getCallableRefForConstructor"; private static final String CALLABLE_REF_FOR_TOP_LEVEL_PROPERTY = "getCallableRefForTopLevelProperty"; private static final String CALLABLE_REF_FOR_MEMBER_PROPERTY = "getCallableRefForMemberProperty"; @@ -261,6 +262,8 @@ public final class Namer { @NotNull private final JsName callableRefForExtensionFunctionName; @NotNull + private final JsName callableRefForLocalExtensionFunctionName; + @NotNull private final JsName callableRefForConstructorName; @NotNull private final JsName callableRefForTopLevelProperty; @@ -295,6 +298,7 @@ public final class Namer { objectName = kotlinScope.declareName(OBJECT_OBJECT_NAME); callableRefForMemberFunctionName = kotlinScope.declareName(CALLABLE_REF_FOR_MEMBER_FUNCTION_NAME); callableRefForExtensionFunctionName = kotlinScope.declareName(CALLABLE_REF_FOR_EXTENSION_FUNCTION_NAME); + callableRefForLocalExtensionFunctionName = kotlinScope.declareName(CALLABLE_REF_FOR_LOCAL_EXTENSION_FUNCTION_NAME); callableRefForConstructorName = kotlinScope.declareName(CALLABLE_REF_FOR_CONSTRUCTOR_NAME); callableRefForTopLevelProperty = kotlinScope.declareName(CALLABLE_REF_FOR_TOP_LEVEL_PROPERTY); callableRefForMemberProperty = kotlinScope.declareName(CALLABLE_REF_FOR_MEMBER_PROPERTY); @@ -344,6 +348,11 @@ public final class Namer { return kotlin(callableRefForExtensionFunctionName); } + @NotNull + public JsExpression callableRefForLocalExtensionFunctionReference() { + return kotlin(callableRefForLocalExtensionFunctionName); + } + @NotNull public JsExpression callableRefForConstructorReference() { return kotlin(callableRefForConstructorName); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt index 05541d35f27..bfc9d85fda0 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt @@ -130,15 +130,18 @@ object CallableReferenceTranslator { assert(receiverParameterDescriptor != null, "receiverParameter for extension should not be null") val jsFunctionRef = ReferenceTranslator.translateAsFQReference(descriptor, context) - if (descriptor.getVisibility() == Visibilities.LOCAL) - return jsFunctionRef + if (descriptor.getVisibility() == Visibilities.LOCAL) { + return JsInvocation(context.namer().callableRefForLocalExtensionFunctionReference(), jsFunctionRef) + } + else if (AnnotationsUtils.isNativeObject(descriptor)) { val jetType = receiverParameterDescriptor!!.getType() val receiverClassDescriptor = DescriptorUtils.getClassDescriptorForType(jetType) return translateAsMemberFunctionReference(descriptor, receiverClassDescriptor, context) } - else + else { return JsInvocation(context.namer().callableRefForExtensionFunctionReference(), jsFunctionRef) + } } private fun translateForMemberFunction(descriptor: FunctionDescriptor, context: TranslationContext): JsExpression { diff --git a/js/js.translator/testData/callableReference/function/cases/abstractClassMember.kt b/js/js.translator/testData/callableReference/function/cases/abstractClassMember.kt index e9a395ff2d1..d06c57e9ea9 100644 --- a/js/js.translator/testData/callableReference/function/cases/abstractClassMember.kt +++ b/js/js.translator/testData/callableReference/function/cases/abstractClassMember.kt @@ -9,4 +9,4 @@ class B : A() { override fun foo() = "OK" } -fun box(): String = B().(A::foo)() +fun box(): String = (A::foo)(B()) diff --git a/js/js.translator/testData/callableReference/function/cases/booleanNotIntrinsic.kt b/js/js.translator/testData/callableReference/function/cases/booleanNotIntrinsic.kt index e08772611c0..1366015c246 100644 --- a/js/js.translator/testData/callableReference/function/cases/booleanNotIntrinsic.kt +++ b/js/js.translator/testData/callableReference/function/cases/booleanNotIntrinsic.kt @@ -2,7 +2,7 @@ package foo fun box(): String { - if (true.(Boolean::not)() != false) return "Fail 1" - if (false.(Boolean::not)() != true) return "Fail 2" + if ((Boolean::not)(true) != false) return "Fail 1" + if ((Boolean::not)(false) != true) return "Fail 2" return "OK" } diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberAndExtension.kt b/js/js.translator/testData/callableReference/function/cases/classMemberAndExtension.kt index e3297fc6d7e..bcf27dd2b3c 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberAndExtension.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberAndExtension.kt @@ -12,14 +12,14 @@ fun box():String { val a = A() - var r = a.(A::memBar)("!!") + var r = (A::memBar)(a, "!!") if (r != "sA:memBar:!!") return r - r = a.(A::extBar)("!!") + r = (A::extBar)(a, "!!") if (r != "sA:extBar:!!") return r - r = a.(A::locExtBar)("!!") + r = (A::locExtBar)(a, "!!") if (r != "sA:locExtBar:!!") return r return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberAndExtensionCompatibility.kt b/js/js.translator/testData/callableReference/function/cases/classMemberAndNonExtensionCompatibility.kt similarity index 75% rename from js/js.translator/testData/callableReference/function/cases/classMemberAndExtensionCompatibility.kt rename to js/js.translator/testData/callableReference/function/cases/classMemberAndNonExtensionCompatibility.kt index da9091f4f2d..9bb628371d3 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberAndExtensionCompatibility.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberAndNonExtensionCompatibility.kt @@ -1,7 +1,7 @@ package foo -fun run(a: A, arg: String, funRef:A.(String) -> String): String { - return a.(funRef)(arg) +fun run(a: A, arg: String, funRef:(A, String) -> String): String { + return funRef(a, arg) } class A { @@ -25,8 +25,8 @@ fun box():String { r = run(a, "!!", A::locExtBar) if (r != "sA:locExtBar:!!") return r - r = run(a, "!!") {A.(other:String):String -> s + ":literal:" + other } + r = run(a, "!!") {(a: A, other: String): String -> a.s + ":literal:" + other } if (r != "sA:literal:!!") return r return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromClass.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromClass.kt index 437d60f1b74..6ccd9aba4f6 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromClass.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromClass.kt @@ -4,7 +4,7 @@ package foo class A { fun bar(k: Int) = k - fun result() = this.(::bar)(111) + fun result() = (::bar)(this, 111) } fun box(): String { diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromExtension.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromExtension.kt index 3320e69657e..4355161af61 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromExtension.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromExtension.kt @@ -6,7 +6,7 @@ class A { fun k(k: Int) = k } -fun A.bar() = this.(::o)() + this.(A::k)(222) +fun A.bar() = (::o)(this) + (A::k)(this, 222) fun box(): String { val result = A().bar() diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringNoArgs.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringNoArgs.kt index 88c380b34e3..324b957b0af 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringNoArgs.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringNoArgs.kt @@ -1,22 +1,12 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, funRef:A.() -> String): String { - return arg1.funRef() -} - class A { fun foo() = "OK" } fun box(): String { val x = A::foo - var r = A().x() - if (r != "OK") return r - - r = run(A(), A::foo) - if (r != "OK") return r - - return "OK" + var r = x(A()) + return r } - diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringOneStringArg.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringOneStringArg.kt index d38f4139e12..23c5409bd29 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringOneStringArg.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelStringOneStringArg.kt @@ -1,21 +1,13 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String { - return arg1.funRef(arg2) -} - class A { fun foo(result: String):String = result } fun box(): String { val x = A::foo - var r = A().x("OK") + var r = x(A(), "OK") - if (r != "OK") return r - - r = run(A(), "OK", A::foo) - if (r != "OK") return r - return "OK" + return r } diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitNoArgs.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitNoArgs.kt index b9305e91102..a10c1899391 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitNoArgs.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitNoArgs.kt @@ -1,10 +1,6 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, funRef:A.() -> Unit): Unit { - return arg1.funRef() -} - class A { var result = "Fail" @@ -16,14 +12,6 @@ class A { fun box(): String { val a = A() val x = A::foo - a.x() - var r = a.result - if (r != "OK") return r - - val a1 = A() - run(a1, A::foo) - r = a.result - if (r != "OK") return r - - return "OK" + x(a) + return a.result } diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitOneStringArg.kt b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitOneStringArg.kt index 4b5bbcc85dd..88c55e2be28 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitOneStringArg.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberFromTopLevelUnitOneStringArg.kt @@ -1,10 +1,6 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit { - return arg1.funRef(arg2) -} - class A { var result = "Fail" @@ -16,14 +12,6 @@ class A { fun box(): String { val a = A() val x = A::foo - a.x("OK") - var r = a.result - if (r != "OK") return r - - val a1 = A() - run(a1, "OK", A::foo) - r = a1.result - if (r != "OK") return r - - return "OK" + x(a, "OK") + return a.result } diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberOverridden.kt b/js/js.translator/testData/callableReference/function/cases/classMemberOverridden.kt index b5084c182dd..00fac713bef 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberOverridden.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberOverridden.kt @@ -11,6 +11,6 @@ class B : A() { fun box(): String { val b = B() var ref = A::foo - val result = b.(ref)("1", "2") + val result = ref(b, "1", "2") return (if (result == "fooB:12") "OK" else result) } diff --git a/js/js.translator/testData/callableReference/function/cases/classMemberOverriddenInObject.kt b/js/js.translator/testData/callableReference/function/cases/classMemberOverriddenInObject.kt index ac2a4f3716f..0ad39d5ad91 100644 --- a/js/js.translator/testData/callableReference/function/cases/classMemberOverriddenInObject.kt +++ b/js/js.translator/testData/callableReference/function/cases/classMemberOverriddenInObject.kt @@ -10,6 +10,6 @@ object B : A() { fun box(): String { var ref = B::foo - val result = B.(ref)("1", "2") + val result = ref(B, "1", "2") return (if (result == "fooB:12") "OK" else result) } diff --git a/js/js.translator/testData/callableReference/function/cases/extension.kt b/js/js.translator/testData/callableReference/function/cases/extension.kt index 704a1f0b8c4..ad6c89fab9d 100644 --- a/js/js.translator/testData/callableReference/function/cases/extension.kt +++ b/js/js.translator/testData/callableReference/function/cases/extension.kt @@ -5,5 +5,5 @@ class A fun box(): String { fun A.foo() = "OK" - return A().(A::foo)() + return (A::foo)(A()) } diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromClass.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromClass.kt index 03d12c89dc1..80806ebd149 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromClass.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromClass.kt @@ -2,7 +2,7 @@ package foo class A { - fun result() = this.(::bar)("OK") + fun result() = (::bar)(this, "OK") } fun A.bar(x: String) = x diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromExtension.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromExtension.kt index 39f76b5b8a6..17fab022176 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromExtension.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromExtension.kt @@ -3,7 +3,7 @@ package foo class A -fun A.foo() = this.(A::bar)("OK") +fun A.foo() = (A::bar)(this, "OK") fun A.bar(x: String) = x diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevel.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevel.kt index 01468e38276..797f52eda1d 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevel.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevel.kt @@ -1,8 +1,8 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, arg2: T, funRef:A.(T) -> T): T { - return arg1.funRef(arg2) +fun run(arg1: A, arg2: T, funRef:(A, T) -> T): T { + return funRef(arg1, arg2) } class A { @@ -17,9 +17,9 @@ fun A.bar(x: Int): Int { fun box(): Boolean { val funRef = A::bar val obj = A() - var result = obj.(funRef)(25) + var result = funRef(obj, 25) if (result != 25 || obj.xx != 200) return false result = run(A(), 25, funRef) return result == 25 && obj.xx == 200 -} \ No newline at end of file +} diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringNoArgs.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringNoArgs.kt index 26a597855d3..8b5bcd4e06e 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringNoArgs.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringNoArgs.kt @@ -11,7 +11,7 @@ fun A.foo() = "OK" fun box(): String { val x = A::foo - var r = A().x() + var r = x(A()) if (r != "OK") return r r = run(A(), A::foo) diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringOneStringArg.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringOneStringArg.kt index 3c4d6976e6f..cdcb5d09a0a 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringOneStringArg.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelStringOneStringArg.kt @@ -11,7 +11,7 @@ fun A.foo(result: String) = result fun box(): String { val x = A::foo - var r = A().x("OK") + var r = x(A(), "OK") if (r != "OK") return r r = run(A(), "OK", A::foo) diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitNoArgs.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitNoArgs.kt index 4ca7aa999f6..5feb3ac7d12 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitNoArgs.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitNoArgs.kt @@ -1,10 +1,6 @@ // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/. package foo -fun run(arg1: A, funRef:A.() -> Unit): Unit { - return arg1.funRef() -} - class A { var result = "Fail" } @@ -16,11 +12,7 @@ fun A.foo() { fun box(): String { val a = A() val x = A::foo - a.x() + x(a) - if (a.result != "OK") return a.result - - val a1 = A() - run(a1, A::foo) return a.result } diff --git a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitOneStringArg.kt b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitOneStringArg.kt index 303595bd7fd..025c997a3db 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitOneStringArg.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionFromTopLevelUnitOneStringArg.kt @@ -16,7 +16,7 @@ fun A.foo(newResult: String) { fun box(): String { val a = A() val x = A::foo - a.x("OK") + x(a, "OK") if (a.result != "OK") return a.result diff --git a/js/js.translator/testData/callableReference/function/cases/extensionToPrimitive.kt b/js/js.translator/testData/callableReference/function/cases/extensionToPrimitive.kt index f4d9ebc8410..d47f70664cf 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionToPrimitive.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionToPrimitive.kt @@ -3,5 +3,5 @@ package foo fun box(): String { fun Int.is42With(that: Int) = this + 2 * that == 42 - return if (16.(Int::is42With)(13)) "OK" else "Fail" + return if ((Int::is42With)(16, 13)) "OK" else "Fail" } diff --git a/js/js.translator/testData/callableReference/function/cases/extensionWithClosure.kt b/js/js.translator/testData/callableReference/function/cases/extensionWithClosure.kt index 03db48e36ae..dc0bf4868f9 100644 --- a/js/js.translator/testData/callableReference/function/cases/extensionWithClosure.kt +++ b/js/js.translator/testData/callableReference/function/cases/extensionWithClosure.kt @@ -9,6 +9,6 @@ fun box(): String { fun A.ext() { result = "OK" } val f = A::ext - A().f() + f(A()) return result } diff --git a/js/js.translator/testData/callableReference/function/cases/localAndTopLevelExtensions.kt b/js/js.translator/testData/callableReference/function/cases/localAndTopLevelExtensions.kt index 49b58d9439d..9ccfd7ef4e1 100644 --- a/js/js.translator/testData/callableReference/function/cases/localAndTopLevelExtensions.kt +++ b/js/js.translator/testData/callableReference/function/cases/localAndTopLevelExtensions.kt @@ -1,6 +1,6 @@ package foo -fun Int.sum0(other: Int): Int = this + other; +fun Int.sum0(other: Int): Int = this + other fun box(): String { fun Int.sum1(other: Int): Int = this + other @@ -13,8 +13,8 @@ fun box(): String { x = x.sum2(5) var y = 10 - y = y.(Int::sum0)(5) - y = y.(Int::sum1)(5) + y = (Int::sum0)(y, 5) + y = (Int::sum1)(y, 5) y = y.sum2(5) var result:String = (if (x == y && x == 25) "OK" else "x=${x} y=${y}") diff --git a/js/js.translator/testData/callableReference/function/cases/stringNativeExtension.kt b/js/js.translator/testData/callableReference/function/cases/stringNativeExtension.kt index 52a1655a976..8153191281f 100644 --- a/js/js.translator/testData/callableReference/function/cases/stringNativeExtension.kt +++ b/js/js.translator/testData/callableReference/function/cases/stringNativeExtension.kt @@ -2,7 +2,7 @@ package foo fun box(): String { var s = "abc" - assertEquals("ABC", s.(String::toUpperCase)()) + assertEquals("ABC", (String::toUpperCase)(s)) return "OK" } diff --git a/js/js.translator/testData/expression/invoke/cases/invokeWithImplicitDispatchReceiverAndExtensionReceiver.kt b/js/js.translator/testData/expression/invoke/cases/invokeWithImplicitDispatchReceiverAndExtensionReceiver.kt index d0f0c2b23ba..5c32ed9f60b 100644 --- a/js/js.translator/testData/expression/invoke/cases/invokeWithImplicitDispatchReceiverAndExtensionReceiver.kt +++ b/js/js.translator/testData/expression/invoke/cases/invokeWithImplicitDispatchReceiverAndExtensionReceiver.kt @@ -3,10 +3,10 @@ package foo fun A.f(s: String) = value + s class A(val value: String) { - fun bar(s: String) = (::f)(s) + fun bar(s: String) = (::f)(this, s) } -fun A.baz(s: String) = (::f)(s) +fun A.baz(s: String) = (::f)(this, s) fun box(): String { val a = A("aaa") diff --git a/js/js.translator/testData/kotlin_lib_ecma5.js b/js/js.translator/testData/kotlin_lib_ecma5.js index fb93b455480..e0c62d82ba2 100644 --- a/js/js.translator/testData/kotlin_lib_ecma5.js +++ b/js/js.translator/testData/kotlin_lib_ecma5.js @@ -337,7 +337,9 @@ var Kotlin = {}; // TODO Store callable references for members in class Kotlin.getCallableRefForMemberFunction = function (klass, memberName) { return function () { - return this[memberName].apply(this, arguments); + var args = [].slice.call(arguments); + var instance = args.shift(); + return instance[memberName].apply(instance, args); }; }; @@ -345,9 +347,15 @@ var Kotlin = {}; // extFun expected receiver as the first argument Kotlin.getCallableRefForExtensionFunction = function (extFun) { return function () { - var args = [this]; - Array.prototype.push.apply(args, arguments); - return extFun.apply(null, args); + return extFun.apply(null, arguments); + }; + }; + + Kotlin.getCallableRefForLocalExtensionFunction = function (extFun) { + return function () { + var args = [].slice.call(arguments); + var instance = args.shift(); + return extFun.apply(instance, args); }; }; diff --git a/js/js.translator/testData/multiPackage/cases/reflectionFromOtherPackage/b.kt b/js/js.translator/testData/multiPackage/cases/reflectionFromOtherPackage/b.kt index cbc31257a28..625ccbd9772 100644 --- a/js/js.translator/testData/multiPackage/cases/reflectionFromOtherPackage/b.kt +++ b/js/js.translator/testData/multiPackage/cases/reflectionFromOtherPackage/b.kt @@ -7,9 +7,9 @@ fun A.ext2(s: String): String = "A.ext2: ${this.v} ${s}" fun box(): Boolean { assertEquals("topLevelFun: A", (::topLevelFun)("A")) - assertEquals("A.ext1: test B", A("test").(A::ext1)("B")) - assertEquals("A.ext2: test B", A("test").(A::ext2)("B")) - assertEquals("memA: test C", A("test").(A::memA)("C")) + assertEquals("A.ext1: test B", (A::ext1)(A("test"), "B")) + assertEquals("A.ext2: test B", (A::ext2)(A("test"), "B")) + assertEquals("memA: test C", (A::memA)(A("test"), "C")) assertEquals(100, ::topLevelVar.get()) ::topLevelVar.set(500) @@ -25,5 +25,5 @@ fun box(): Boolean { (A::extProp).set(a, "new text") assertEquals("new text", (A::extProp).get(a)) - return true; -} \ No newline at end of file + return true +} diff --git a/js/js.translator/testData/native/cases/nativeExtensionLikeMember.kt b/js/js.translator/testData/native/cases/nativeExtensionLikeMember.kt index d088358614c..956da932d1f 100644 --- a/js/js.translator/testData/native/cases/nativeExtensionLikeMember.kt +++ b/js/js.translator/testData/native/cases/nativeExtensionLikeMember.kt @@ -22,8 +22,8 @@ fun box(): String { assertEquals("A.bar A", a.bar()) assertEquals("B.bar B", b.bar()) - assertEquals("A.bar A", a.(A::bar)()) - assertEquals("B.bar B", b.(A::bar)()) + assertEquals("A.bar A", (A::bar)(a)) + assertEquals("B.bar B", (A::bar)(b)) a.prop = "prop" assertEquals("prop", a.prop) @@ -31,10 +31,10 @@ fun box(): String { a = b assertEquals("B.bar B", a.bar()) - assertEquals("B.bar B", a.(A::bar)()) + assertEquals("B.bar B", (A::bar)(a)) assertEquals("B prop", a.prop) assertEquals("B prop", (A::prop).get(a)) - return "OK"; + return "OK" } diff --git a/js/js.translator/testData/native/cases/passMemberOrExtFromNative.kt b/js/js.translator/testData/native/cases/passMemberOrExtFromNative.kt index 8cca0493769..fb70ffbc1b2 100644 --- a/js/js.translator/testData/native/cases/passMemberOrExtFromNative.kt +++ b/js/js.translator/testData/native/cases/passMemberOrExtFromNative.kt @@ -16,13 +16,13 @@ fun box(): String { val a = A("test") assertEquals("A.m test 4 boo", a.m(4, "boo")) - assertEquals("A.m test 4 boo", bar(a, A::m)) + assertEquals("A.m test 4 boo", bar(a, fun A.(i, s) = (A::m)(this, i, s))) assertEquals("nativeExt test 4 boo", a.nativeExt(4, "boo")) - assertEquals("nativeExt test 4 boo", bar(a, A::nativeExt)) + assertEquals("nativeExt test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt)(this, i, s))) assertEquals("nativeExt2 test 4 boo", a.nativeExt2(4, "boo")) - assertEquals("nativeExt2 test 4 boo", bar(a, A::nativeExt2)) + assertEquals("nativeExt2 test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt2)(this, i, s))) return "OK" } diff --git a/js/js.translator/testData/native/cases/passMemberOrExtToNative.kt b/js/js.translator/testData/native/cases/passMemberOrExtToNative.kt index 125a2c5eeed..57c1f0e0e5d 100644 --- a/js/js.translator/testData/native/cases/passMemberOrExtToNative.kt +++ b/js/js.translator/testData/native/cases/passMemberOrExtToNative.kt @@ -21,18 +21,18 @@ fun box(): String { fun A.LocalExt(i:Int, s:String): String = "A::LocalExt ${this.v} $i $s" - r = bar(a, A::topLevelExt) + r = bar(a, fun A.(i, s) = (A::topLevelExt)(this, i, s)) if (r != "A::topLevelExt test 4 boo") return r - r = bar(a, A::LocalExt) + r = bar(a, fun A.(i, s) = (A::LocalExt)(this, i, s)) if (r != "A::LocalExt test 4 boo") return r - r = bar(a, A::m) + r = bar(a, fun A.(i, s) = (A::m)(this, i, s)) if (r != "A.m test 4 boo") return r val b = B("test") - r = bar(b, A::m) + r = bar(b, fun A.(i, s) = (A::m)(this, i, s)) if (r != "B.m test 4 boo") return r return "OK" -} \ No newline at end of file +}