K2: resolve remove(Int) clash in JavaOverrideChecker
In Kotlin subclasses of `MutableCollection<Int>`, the method `remove(Int)` has its argument boxed, so that it wouldn't clash with the method from `java.util.List`. So `JavaOverrideChecker` should understand that a Java method `boolean remove(java.lang.Integer)` overrides it, otherwise platform declaration clash was reported. The code is adapted from `forceSingleValueParameterBoxing` in K1's `methodSignatureMapping.kt`. The test has been moved and adapted from diagnostic to codegen box tests, to check correct backend execution + runtime. #KT-62316 Fixed
This commit is contained in:
committed by
Space Team
parent
8e023edc4f
commit
2788dcb5ff
@@ -0,0 +1,59 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
abstract public class A extends B {
|
||||
public Integer removeAt(int x) { return 0; }
|
||||
public boolean remove(Integer x) { return false; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import java.util.*;
|
||||
|
||||
abstract class B : MutableList<Int>, AbstractList<Int>() {
|
||||
override fun removeAt(index: Int): Int = null!!
|
||||
override fun remove(element: Int): Boolean = null!!
|
||||
}
|
||||
|
||||
abstract class D : AbstractList<Int>() {
|
||||
// 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 = 0
|
||||
// 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 = false
|
||||
}
|
||||
|
||||
fun testABD(a: A, b: B, d: D) {
|
||||
a.remove(1)
|
||||
a.removeAt(0)
|
||||
b.remove(1)
|
||||
b.removeAt(0)
|
||||
d.remove(1)
|
||||
d.removeAt(0)
|
||||
}
|
||||
|
||||
fun testArrayList(c: ArrayList<Int>) {
|
||||
c.remove(1)
|
||||
c.removeAt(0)
|
||||
}
|
||||
|
||||
class AImpl : A() {
|
||||
override fun get(index: Int): Int = 0
|
||||
override val size: Int get() = 0
|
||||
}
|
||||
|
||||
class DImpl : D() {
|
||||
override fun get(index: Int): Int = 0
|
||||
override val size: Int get() = 0
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testABD(AImpl(), AImpl(), DImpl())
|
||||
|
||||
val c = ArrayList<Int>()
|
||||
c.add(1)
|
||||
c.add(1)
|
||||
testArrayList(c)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
// FILE: IntOpenHashSet.java
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class IntOpenHashSet extends AbstractIntSet {
|
||||
@Override
|
||||
public boolean remove(final int k) { return false; }
|
||||
|
||||
@Override
|
||||
public void clear() {}
|
||||
|
||||
@Override
|
||||
public int size() { return 0; }
|
||||
|
||||
@Override
|
||||
public Iterator<Integer> iterator() { return null; }
|
||||
}
|
||||
|
||||
abstract class AbstractIntSet extends AbstractIntCollection implements IntSet {
|
||||
@Override
|
||||
public boolean remove(int k) { return false; }
|
||||
}
|
||||
|
||||
abstract class AbstractIntCollection extends AbstractCollection<Integer> implements IntCollection {}
|
||||
|
||||
interface IntCollection extends Collection<Integer> {}
|
||||
|
||||
interface IntSet extends IntCollection, Set<Integer> {
|
||||
boolean remove(int k);
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
fun box(): String {
|
||||
val s = IntOpenHashSet()
|
||||
s.remove(0)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user