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"
|
||||
}
|
||||
Reference in New Issue
Block a user