IR: copy EnhancedNullability in CopyIrTreeWithSymbolsForFakeOverrides

Otherwise it leads to the following problem in the newly added test.

Suppose that we have a fake override `remove(Int)` inherited from
LinkedList _without_ EnhancedNullability on its parameter type. By
normal Kotlin rules, this method should override the method from
KotlinInterface. However, on JVM we have another overridability check in
IrJavaIncompatibilityRulesOverridabilityCondition which ensures that
"JVM primitivity" of parameter types is the same for the base and the
overridden method.

So the fake override `remove(Int)` from LinkedList is determined to be
override-incompatible with `remove(Int)` from KotlinInterface. But when
we try to create symbols for all fake overrides in the class, we get a
clash because there are two fake overrides with exactly the same
IdSignature, neither of which overrides the other.

If we keep the EnhancedNullability annotation on the parameter, it
starts working because the logic of computing signature in
JvmIrMangler.JvmIrManglerComputer.mangleTypePlatformSpecific adds an
"{EnhancedNullability}" mark to the IdSignature of a fake override from
LinkedList.

 #KT-65499 Fixed
This commit is contained in:
Alexander Udalov
2024-02-02 15:41:43 +01:00
committed by Space Team
parent f05c972efb
commit 53c5230520
14 changed files with 188 additions and 103 deletions
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// FULL_JDK
import java.util.LinkedList
interface KotlinInterface {
fun remove(i: Int): Boolean
}
var result = "Fail"
abstract class C : LinkedList<Int>(), KotlinInterface
class D : C() {
override fun remove(i: Int): Boolean {
result = "OK"
return true
}
}
fun box(): String {
D().remove(0)
return result
}