Introduce fictitious numbered Function class descriptors
This commit is contained in:
@@ -28,11 +28,12 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.JetTypeImpl;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
@@ -94,30 +95,40 @@ public class JvmRuntimeTypes {
|
||||
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
|
||||
ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();
|
||||
|
||||
List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);
|
||||
|
||||
ClassDescriptor kFunctionClass;
|
||||
ClassDescriptor functionImplClass;
|
||||
JetType receiverType;
|
||||
if (extensionReceiver != null) {
|
||||
functionImplClass = extensionFunctionImpl;
|
||||
receiverType = extensionReceiver.getType();
|
||||
kFunctionClass = reflectionTypes.getkExtensionFunction();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else if (dispatchReceiver != null) {
|
||||
functionImplClass = memberFunctionImpl;
|
||||
receiverType = dispatchReceiver.getType();
|
||||
kFunctionClass = reflectionTypes.getkMemberFunction();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else {
|
||||
functionImplClass = functionImpl;
|
||||
receiverType = null;
|
||||
kFunctionClass = reflectionTypes.getkFunction();
|
||||
}
|
||||
|
||||
JetType functionImplType = functionImplClass.getDefaultType();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
JetType kFunctionType = reflectionTypes.getKFunctionType(
|
||||
Annotations.EMPTY,
|
||||
receiverType,
|
||||
ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
|
||||
descriptor.getReturnType(),
|
||||
extensionReceiver != null
|
||||
typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));
|
||||
|
||||
JetType kFunctionType = new JetTypeImpl(
|
||||
kFunctionClass.getDefaultType().getAnnotations(),
|
||||
kFunctionClass.getTypeConstructor(),
|
||||
false,
|
||||
typeArguments,
|
||||
kFunctionClass.getMemberScope(typeArguments)
|
||||
);
|
||||
|
||||
return Arrays.asList(functionImplType, kFunctionType);
|
||||
|
||||
@@ -256,7 +256,7 @@ public class InlineCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String prefix : Arrays.asList("kotlin/Function", "kotlin/ExtensionFunction")) {
|
||||
for (String prefix : Arrays.asList("kotlin/jvm/functions/Function", "kotlin/ExtensionFunction")) {
|
||||
if (owner.startsWith(prefix)) {
|
||||
String suffix = owner.substring(prefix.length());
|
||||
if (isInteger(suffix)) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
||||
import org.jetbrains.kotlin.codegen.binding.MutableClosure;
|
||||
@@ -595,7 +596,9 @@ public class JetTypeMapper {
|
||||
|
||||
signature = mapSignature(functionDescriptor.getOriginal());
|
||||
|
||||
ClassDescriptor receiver = currentIsInterface && !originalIsInterface ? declarationOwner : currentOwner;
|
||||
ClassDescriptor receiver = (currentIsInterface && !originalIsInterface) || currentOwner instanceof FunctionClassDescriptor
|
||||
? declarationOwner
|
||||
: currentOwner;
|
||||
owner = mapClass(receiver);
|
||||
thisClass = owner;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ fun check(expected: String, obj: Any?) {
|
||||
|
||||
|
||||
fun box(): String {
|
||||
check("kotlin.Function0<kotlin.Unit>")
|
||||
check("kotlin.jvm.functions.Function0<kotlin.Unit>")
|
||||
{ -> }
|
||||
check("kotlin.Function0<java.lang.Integer>")
|
||||
{ -> 42 }
|
||||
check("kotlin.Function1<java.lang.String, java.lang.Long>",
|
||||
check("kotlin.jvm.functions.Function0<java.lang.Integer>")
|
||||
{ -> 42 }
|
||||
check("kotlin.jvm.functions.Function1<java.lang.String, java.lang.Long>",
|
||||
fun (s: String) = 42.toLong())
|
||||
check("kotlin.Function2<java.lang.Integer, java.lang.Integer, kotlin.Unit>")
|
||||
check("kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, kotlin.Unit>")
|
||||
{ x: Int, y: Int -> }
|
||||
|
||||
check("kotlin.ExtensionFunction0<java.lang.Integer, kotlin.Unit>",
|
||||
@@ -25,4 +25,4 @@ fun box(): String {
|
||||
fun Int.(x: Int, y: Int) {})
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ val extensionFun = fun Any.() {}
|
||||
val extensionWithArgFun = fun Long.(x: Any): Date = Date()
|
||||
|
||||
fun box(): String {
|
||||
assertGenericSuper("kotlin.Function0<kotlin.Unit>", unitFun)
|
||||
assertGenericSuper("kotlin.Function0<java.lang.Integer>", intFun)
|
||||
assertGenericSuper("kotlin.Function1<java.lang.String, kotlin.Unit>", stringParamFun)
|
||||
assertGenericSuper("kotlin.Function1<java.util.List<? extends java.lang.String>, java.util.List<? extends java.lang.String>>", listFun)
|
||||
assertGenericSuper("kotlin.Function1<java.util.List<java.lang.Double>, java.util.List<java.lang.Integer>>", mutableListFun)
|
||||
assertGenericSuper("kotlin.Function1<java.lang.Comparable<? super java.lang.String>, kotlin.Unit>", funWithIn)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function0<kotlin.Unit>", unitFun)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function0<java.lang.Integer>", intFun)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function1<java.lang.String, kotlin.Unit>", stringParamFun)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function1<java.util.List<? extends java.lang.String>, java.util.List<? extends java.lang.String>>", listFun)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function1<java.util.List<java.lang.Double>, java.util.List<java.lang.Integer>>", mutableListFun)
|
||||
assertGenericSuper("kotlin.jvm.functions.Function1<java.lang.Comparable<? super java.lang.String>, kotlin.Unit>", funWithIn)
|
||||
|
||||
assertGenericSuper("kotlin.ExtensionFunction0<java.lang.Object, kotlin.Unit>", extensionFun)
|
||||
assertGenericSuper("kotlin.ExtensionFunction1<java.lang.Long, java.lang.Object, java.util.Date>", extensionWithArgFun)
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ class Super {
|
||||
}
|
||||
|
||||
class Sub extends Super {
|
||||
void foo(kotlin.Function0<kotlin.Unit> r) {
|
||||
void foo(kotlin.jvm.functions.Function0<kotlin.Unit> r) {
|
||||
lastCalled = "sub";
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,11 +4,11 @@ import java.lang.String;
|
||||
import java.lang.UnsupportedOperationException;
|
||||
import java.util.*;
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
import kotlin.*;
|
||||
import kotlin.jvm.functions.*;
|
||||
|
||||
public class MethodWithFunctionTypes {
|
||||
@KotlinSignature("fun foo(f : (String?) -> String) : (String.() -> String?)?")
|
||||
public ExtensionFunction0<String, String> foo(Function1<String, String> f) {
|
||||
@KotlinSignature("fun foo(f : (String?) -> String) : (() -> String?)?")
|
||||
public Function0<String> foo(Function1<String, String> f) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package test
|
||||
|
||||
public open class MethodWithFunctionTypes {
|
||||
public constructor MethodWithFunctionTypes()
|
||||
public open fun foo(/*0*/ f: ((kotlin.String!) -> kotlin.String!)!): (kotlin.String!.() -> kotlin.String!)!
|
||||
public open fun foo(/*0*/ f: ((kotlin.String!) -> kotlin.String!)!): (() -> kotlin.String!)!
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package test;
|
||||
|
||||
public interface AdapterDoesntOverrideDeclaration {
|
||||
public interface Super {
|
||||
void foo(kotlin.Function0<kotlin.Unit> r);
|
||||
void foo(kotlin.jvm.functions.Function0<kotlin.Unit> r);
|
||||
}
|
||||
|
||||
public interface Sub extends Super {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package test;
|
||||
public interface InheritedAdapterAndDeclaration {
|
||||
public interface Super {
|
||||
void foo(Runnable r);
|
||||
void foo(kotlin.Function0<kotlin.Unit> r);
|
||||
void foo(kotlin.jvm.functions.Function0<kotlin.Unit> r);
|
||||
}
|
||||
|
||||
public interface Sub extends Super {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ public interface InheritedOverriddenAdapter {
|
||||
}
|
||||
|
||||
public class Sub extends Super {
|
||||
public void foo(kotlin.Function0<kotlin.Unit> r) {
|
||||
public void foo(kotlin.jvm.functions.Function0<kotlin.Unit> r) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ public interface OverriddenAmbiguousAdapters {
|
||||
}
|
||||
|
||||
public interface Sub extends Super {
|
||||
void foo(kotlin.Function0<kotlin.Unit> r);
|
||||
void foo(kotlin.jvm.functions.Function0<kotlin.Unit> r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class OuterClassGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testLocalObjectInInlineFunction() throws Exception {
|
||||
OuterClassInfo expectedInfo = new OuterClassInfo("foo/Foo", "inlineFoo", "(Lkotlin/Function0;)V");
|
||||
OuterClassInfo expectedInfo = new OuterClassInfo("foo/Foo", "inlineFoo", "(Lkotlin/jvm/functions/Function0;)V");
|
||||
doCustomTest("foo/Foo\\$inlineFoo\\$localObject\\$1", expectedInfo, "inlineObject");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class OuterClassGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testLambdaInInlineFunction() throws Exception {
|
||||
OuterClassInfo expectedInfo = new OuterClassInfo("foo/Foo", "inlineFoo", "(Lkotlin/Function0;)V");
|
||||
OuterClassInfo expectedInfo = new OuterClassInfo("foo/Foo", "inlineFoo", "(Lkotlin/jvm/functions/Function0;)V");
|
||||
doCustomTest("foo/Foo\\$inlineFoo\\$1", expectedInfo, "inlineLambda");
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.createBuiltInPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.TEST_PACKAGE_FQNAME
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDescriptorFactory
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
@@ -39,11 +40,12 @@ public class BuiltInsSerializerTest : TestCaseWithTmpdir() {
|
||||
|
||||
val module = JetTestUtils.createEmptyModule("<module>")
|
||||
|
||||
val packageFragmentProvider =
|
||||
createBuiltInPackageFragmentProvider(LockBasedStorageManager(), module, setOf(TEST_PACKAGE_FQNAME)) {
|
||||
val file = File(tmpdir, it)
|
||||
if (file.exists()) FileInputStream(file) else null
|
||||
}
|
||||
val packageFragmentProvider = createBuiltInPackageFragmentProvider(
|
||||
LockBasedStorageManager(), module, setOf(TEST_PACKAGE_FQNAME), ClassDescriptorFactory.EMPTY
|
||||
) {
|
||||
val file = File(tmpdir, it)
|
||||
if (file.exists()) FileInputStream(file) else null
|
||||
}
|
||||
|
||||
module.initialize(packageFragmentProvider)
|
||||
module.addDependencyOnModule(module)
|
||||
|
||||
Reference in New Issue
Block a user