Refine signature mapping for special overrrides from Java
They have special JVM descriptor only when they are not inherited from Kotlin super class
This commit is contained in:
@@ -36,12 +36,13 @@ import org.jetbrains.kotlin.fileClasses.FileClasses;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature;
|
||||
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope;
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.name.*;
|
||||
@@ -782,7 +783,7 @@ public class JetTypeMapper {
|
||||
|
||||
FunctionDescriptor overriddenSpecialBuiltinFunction =
|
||||
SpecialBuiltinMembers.<FunctionDescriptor>getOverriddenBuiltinWithDifferentJvmDescriptor(functionDescriptor.getOriginal());
|
||||
FunctionDescriptor functionToCall = overriddenSpecialBuiltinFunction != null
|
||||
FunctionDescriptor functionToCall = overriddenSpecialBuiltinFunction != null && !superCall
|
||||
? overriddenSpecialBuiltinFunction.getOriginal()
|
||||
: functionDescriptor.getOriginal();
|
||||
|
||||
@@ -943,6 +944,15 @@ public class JetTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
if (f.getOriginal().getSource() instanceof JavaSourceElement) {
|
||||
FunctionDescriptor overridden = SpecialBuiltinMembers.<FunctionDescriptor>getOverriddenBuiltinWithDifferentJvmDescriptor(f);
|
||||
if (overridden != null
|
||||
&& !SpecialBuiltinMembers.hasRealKotlinSuperClassWithOverrideOf(
|
||||
(ClassDescriptor) f.getContainingDeclaration(), overridden)
|
||||
) {
|
||||
return mapSignature(overridden, kind, overridden.getValueParameters());
|
||||
}
|
||||
}
|
||||
if (f instanceof ConstructorDescriptor) {
|
||||
return mapSignature(f, kind, f.getOriginal().getValueParameters());
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class J extends MyList {
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 55;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> subList(int i, int i1) {
|
||||
return super.subList(i, i1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<String> listIterator(int i) {
|
||||
return super.listIterator(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<String> listIterator() {
|
||||
return super.listIterator();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
abstract class MyList : List<String>
|
||||
|
||||
class ListImpl : J() {
|
||||
override val size: Int get() = super.size + 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val impl = ListImpl()
|
||||
if (impl.size != 56) return "fail 1"
|
||||
if (!impl.contains("abc")) return "fail 2"
|
||||
|
||||
val l: List<String> = impl
|
||||
|
||||
if (l.size != 56) return "fail 3"
|
||||
if (!l.contains("abc")) return "fail 4"
|
||||
|
||||
val anyList: List<Any?> = impl as List<Any?>
|
||||
|
||||
if (anyList.size != 56) return "fail 5"
|
||||
if (!anyList.contains("abc")) return "fail 6"
|
||||
|
||||
if (anyList.contains(1)) return "fail 7"
|
||||
if (anyList.contains(null)) return "fail 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ public abstract class MyMap : java.util.AbstractMap<kotlin.Double!, kotlin.CharS
|
||||
public open override /*1*/ /*fake_override*/ fun containsKey(/*0*/ key: kotlin.Double!): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun containsValue(/*0*/ value: kotlin.CharSequence!): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public/*package*/ open override /*1*/ fun get(/*0*/ q: kotlin.Double!): kotlin.String?
|
||||
public/*package*/ open override /*1*/ fun get(/*0*/ key: kotlin.Double!): kotlin.String?
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun put(/*0*/ key: kotlin.Double!, /*1*/ value: kotlin.CharSequence!): kotlin.CharSequence?
|
||||
|
||||
+6
@@ -191,6 +191,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("implementCollectionThroughKotlin")
|
||||
public void testImplementCollectionThroughKotlin() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/implementCollectionThroughKotlin/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("mutableList")
|
||||
public void testMutableList() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/mutableList/");
|
||||
|
||||
+1
-1
@@ -223,7 +223,7 @@ private fun getBuiltinOverriddenThatAffectsJvmName(
|
||||
): CallableMemberDescriptor? {
|
||||
val overriddenBuiltin = callableMemberDescriptor.getOverriddenBuiltinWithDifferentJvmName() ?: return null
|
||||
|
||||
if (callableMemberDescriptor.isFromJavaOrBuiltins()) return overriddenBuiltin
|
||||
if (callableMemberDescriptor.isFromBuiltins()) return overriddenBuiltin
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user