diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt index cff39967a37..eb8e1a4c5d9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt @@ -119,8 +119,7 @@ private fun needGenerateSpecialBridge( return !classDescriptor.hasRealKotlinSuperClassWithOverrideOf(specialCallableDescriptor) && specialCallableDescriptor.modality != Modality.FINAL && reachableDeclarations.none { - it.containingDeclaration is JavaClassDescriptor - && it.modality == Modality.FINAL + it.modality == Modality.FINAL && signatureByDescriptor(it) == overriddenBuiltinSignature } } diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/J.java b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/J.java new file mode 100644 index 00000000000..02f3225135a --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/J.java @@ -0,0 +1,7 @@ +public class J { + public static class A extends AImpl implements CharSequence { + public CharSequence subSequence(int start, int end) { + return null; + } + } +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/irrelevantImplCharSequence.kt b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/irrelevantImplCharSequence.kt new file mode 100644 index 00000000000..86867647d70 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/irrelevantImplCharSequence.kt @@ -0,0 +1,18 @@ +abstract class AImpl { + fun charAt(index: Int): Char { + return 'A' + } + + fun length(): Int { + return 56 + } +} + +class X : J.A() + +fun box(): String { + val x = X() + if (x.length != 56) return "fail 1" + if (x[0] != 'A') return "fail 2" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/J.java b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/J.java new file mode 100644 index 00000000000..b5c6b17aef3 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/J.java @@ -0,0 +1,99 @@ +import java.util.*; +public class J { + abstract static public class AImpl { + public final int size() { + return 56; + } + + public boolean isEmpty() { + return false; + } + + public final boolean contains(Object o) { + return true; + } + + public Iterator iterator() { + return null; + } + + public Object[] toArray() { + return new Object[0]; + } + + public T[] toArray(T[] a) { + return null; + } + + public boolean add(String s) { + return false; + } + + public boolean remove(Object o) { + return false; + } + + public boolean containsAll(Collection c) { + return false; + } + + public boolean addAll(Collection c) { + return false; + } + + public boolean addAll(int index, Collection c) { + return false; + } + + public boolean removeAll(Collection c) { + return false; + } + + public boolean retainAll(Collection c) { + return false; + } + + public void clear() { + + } + + public String get(int index) { + return null; + } + + public String set(int index, String element) { + return null; + } + + public void add(int index, String element) { + + } + + public String remove(int index) { + return null; + } + + public int indexOf(Object o) { + return 0; + } + + public int lastIndexOf(Object o) { + return 0; + } + + public ListIterator listIterator() { + return null; + } + + public ListIterator listIterator(int index) { + return null; + } + + public List subList(int fromIndex, int toIndex) { + return null; + } + } + + public static class A extends AImpl implements List { + } +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/irrelevantImplMutableList.kt b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/irrelevantImplMutableList.kt new file mode 100644 index 00000000000..2b28ae42ed8 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/irrelevantImplMutableList.kt @@ -0,0 +1,10 @@ + +class X : J.A() + +fun box(): String { + val x = X() + if (x.size != 56) return "fail 1" + if (!x.contains("")) return "fail 2" + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/A.java b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/A.java new file mode 100644 index 00000000000..6e788aa2682 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/A.java @@ -0,0 +1,4 @@ +public class A extends AImpl implements java.util.List { + public T[] toArray(T[] a) {return null;} + public Object[] toArray() {return null;} +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/irrelevantImplMutableListKotlin.kt b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/irrelevantImplMutableListKotlin.kt new file mode 100644 index 00000000000..d9bf259991a --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/irrelevantImplMutableListKotlin.kt @@ -0,0 +1,91 @@ +public abstract class AImpl { + fun add(element: String): Boolean { + throw UnsupportedOperationException() + } + + fun remove(element: Any?): Boolean { + throw UnsupportedOperationException() + } + + fun addAll(elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun addAll(index: Int, elements: Collection): Boolean { + throw UnsupportedOperationException() + } + + fun removeAll(elements: Collection<*>): Boolean { + throw UnsupportedOperationException() + } + + fun retainAll(elements: Collection<*>): Boolean { + throw UnsupportedOperationException() + } + + fun clear() { + throw UnsupportedOperationException() + } + + fun set(index: Int, element: String): String { + throw UnsupportedOperationException() + } + + fun add(index: Int, element: String) { + throw UnsupportedOperationException() + } + + fun remove(index: Int): String { + throw UnsupportedOperationException() + } + + fun listIterator(): MutableListIterator { + throw UnsupportedOperationException() + } + + fun listIterator(index: Int): MutableListIterator { + throw UnsupportedOperationException() + } + + fun subList(fromIndex: Int, toIndex: Int): MutableList { + throw UnsupportedOperationException() + } + + fun size(): Int = 56 + + fun isEmpty(): Boolean { + throw UnsupportedOperationException() + } + + fun contains(element: Any?) = true + + fun containsAll(elements: Collection<*>): Boolean { + throw UnsupportedOperationException() + } + + fun get(index: Int): String { + throw UnsupportedOperationException() + } + + fun indexOf(element: Any?): Int { + throw UnsupportedOperationException() + } + + fun lastIndexOf(element: Any?): Int { + throw UnsupportedOperationException() + } + + fun iterator(): MutableIterator { + throw UnsupportedOperationException() + } +} + + +class X : A() + +fun box(): String { + val x = X() + if (x.size != 56) return "fail 1" + if (!x.contains("")) return "fail 2" + return "OK" +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/J.java b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/J.java new file mode 100644 index 00000000000..91037088d37 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/J.java @@ -0,0 +1,99 @@ +import java.util.*; +public class J { + abstract static public class AImpl { + public int size() { + return 56; + } + + public boolean isEmpty() { + return false; + } + + public final boolean contains(Object o) { + return true; + } + + public Iterator iterator() { + return null; + } + + public Object[] toArray() { + return new Object[0]; + } + + public T[] toArray(T[] a) { + return null; + } + + public boolean add(E s) { + return false; + } + + public boolean remove(Object o) { + return false; + } + + public boolean containsAll(Collection c) { + return false; + } + + public boolean addAll(Collection c) { + return false; + } + + public boolean addAll(int index, Collection c) { + return false; + } + + public boolean removeAll(Collection c) { + return false; + } + + public boolean retainAll(Collection c) { + return false; + } + + public void clear() { + + } + + public E get(int index) { + return null; + } + + public E set(int index, E element) { + return null; + } + + public void add(int index, E element) { + + } + + public E remove(int index) { + return null; + } + + public int indexOf(Object o) { + return 0; + } + + public int lastIndexOf(Object o) { + return 0; + } + + public ListIterator listIterator() { + return null; + } + + public ListIterator listIterator(int index) { + return null; + } + + public List subList(int fromIndex, int toIndex) { + return null; + } + } + + public static class A extends AImpl implements List { + } +} diff --git a/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/irrelevantImplMutableListSubstitution.kt b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/irrelevantImplMutableListSubstitution.kt new file mode 100644 index 00000000000..aa2075cc778 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/irrelevantImplMutableListSubstitution.kt @@ -0,0 +1,10 @@ + +class X : J.A() + +fun box(): String { + val x = X() + if (x.size != 56) return "fail 1" + if (!x.contains(null)) return "fail 2" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 3b2df98ae08..bf01756092c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -215,6 +215,30 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("irrelevantImplCharSequenceKotlin") + public void testIrrelevantImplCharSequenceKotlin() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantImplCharSequenceKotlin/"); + doTestWithJava(fileName); + } + + @TestMetadata("irrelevantImplMutableList") + public void testIrrelevantImplMutableList() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableList/"); + doTestWithJava(fileName); + } + + @TestMetadata("irrelevantImplMutableListKotlin") + public void testIrrelevantImplMutableListKotlin() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListKotlin/"); + doTestWithJava(fileName); + } + + @TestMetadata("irrelevantImplMutableListSubstitution") + public void testIrrelevantImplMutableListSubstitution() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantImplMutableListSubstitution/"); + doTestWithJava(fileName); + } + @TestMetadata("irrelevantRemoveAtOverrideInJava") public void testIrrelevantRemoveAtOverrideInJava() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantRemoveAtOverrideInJava/");