diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt new file mode 100644 index 00000000000..f57ecfdb76a --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.fir.kt @@ -0,0 +1,32 @@ +// JAVAC_EXPECTED_FILE +// FILE: A.java +abstract public class A extends B { + public Integer removeAt(int x) { } + public boolean remove(Integer x) { } +} + +// FILE: main.kt +import java.util.*; + +abstract class B : MutableList, AbstractList() { + override fun removeAt(index: Int): Int = null!! + override fun remove(element: Int): Boolean = null!! +} + +abstract class D : AbstractList() { + // removeAt() doesn't exist in java/util/AbstractList, it's a + // fake override of the method from kotlin/collections/MutableList + override fun removeAt(index: Int): Int = null!! + // AbstractList::remove() should return Int here. No fake overrides created. + // This may be a bug because the old compiler doesn't report a diagnostic here. + override fun remove(element: Int): Boolean = null!! +} + +fun main(a: A, b: B, c: ArrayList) { + a.remove(1) + a.removeAt(0) + b.remove(1) + b.removeAt(0) + c.remove(1) + c.removeAt(0) +} diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.kt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.kt index 94bdc3eb1bf..8510bc01ac0 100644 --- a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.kt +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // JAVAC_EXPECTED_FILE // FILE: A.java abstract public class A extends B { @@ -11,7 +10,7 @@ import java.util.*; abstract class B : MutableList, AbstractList() { override fun removeAt(index: Int): Int = null!! - override fun remove(element: Int): Boolean = null!! + override fun remove(element: Int): Boolean = null!! } abstract class D : AbstractList() { @@ -20,7 +19,7 @@ abstract class D : AbstractList() { override fun removeAt(index: Int): Int = null!! // AbstractList::remove() should return Int here. No fake overrides created. // This may be a bug because the old compiler doesn't report a diagnostic here. - override fun remove(element: Int): Boolean = null!! + override fun remove(element: Int): Boolean = null!! } fun main(a: A, b: B, c: ArrayList) { diff --git a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt index c59dad6ac4a..df9a38ad1f8 100644 --- a/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt +++ b/compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAtInt.txt @@ -74,3 +74,37 @@ public abstract class B : kotlin.collections.MutableList, java.util. public open override /*1*/ /*fake_override*/ fun toArray(/*0*/ a: kotlin.Array<(out) T!>!): kotlin.Array<(out) T!>! public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String } + +public abstract class D : java.util.AbstractList { + public constructor D() + protected/*protected and package*/ final override /*1*/ /*fake_override*/ var modCount: kotlin.Int + public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int + public open override /*1*/ /*fake_override*/ fun add(/*0*/ index: kotlin.Int, /*1*/ element: kotlin.Int!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun add(/*0*/ element: kotlin.Int!): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun addAll(/*0*/ index: kotlin.Int, /*1*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun addAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun clear(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun contains(/*0*/ element: kotlin.Int!): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): kotlin.Int! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun indexOf(/*0*/ element: kotlin.Int!): kotlin.Int + public open override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun iterator(): kotlin.collections.MutableIterator + public open override /*1*/ /*fake_override*/ fun lastIndexOf(/*0*/ element: kotlin.Int!): kotlin.Int + public open override /*1*/ /*fake_override*/ fun listIterator(): kotlin.collections.MutableListIterator + public open override /*1*/ /*fake_override*/ fun listIterator(/*0*/ index: kotlin.Int): kotlin.collections.MutableListIterator + invisible_fake open override /*1*/ /*fake_override*/ fun outOfBoundsMsg(/*0*/ index: kotlin.Int): kotlin.String! + invisible_fake open override /*1*/ /*fake_override*/ fun rangeCheckForAdd(/*0*/ index: kotlin.Int): kotlin.Unit + public open override /*1*/ fun remove(/*0*/ element: kotlin.Int): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun removeAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ fun removeAt(/*0*/ index: kotlin.Int): kotlin.Int + protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun removeRange(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun retainAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun set(/*0*/ index: kotlin.Int, /*1*/ element: kotlin.Int!): kotlin.Int! + public open override /*1*/ /*fake_override*/ fun subList(/*0*/ fromIndex: kotlin.Int, /*1*/ toIndex: kotlin.Int): kotlin.collections.MutableList + public open override /*1*/ /*fake_override*/ fun toArray(): kotlin.Array<(out) kotlin.Any!>! + public open override /*1*/ /*fake_override*/ fun toArray(/*0*/ a: kotlin.Array<(out) T!>!): kotlin.Array<(out) T!>! + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +}