Take into account irrelevant implementation of special builtins
This commit is contained in:
@@ -61,7 +61,8 @@ object BuiltinSpecialBridgesUtil {
|
|||||||
// e.g. `size()I`
|
// e.g. `size()I`
|
||||||
val overriddenBuiltinSignature = signatureByDescriptor(overriddenBuiltin)
|
val overriddenBuiltinSignature = signatureByDescriptor(overriddenBuiltin)
|
||||||
|
|
||||||
val needGenerateSpecialBridge = needGenerateSpecialBridge(function, reachableDeclarations, overriddenBuiltin)
|
val needGenerateSpecialBridge = needGenerateSpecialBridge(
|
||||||
|
function, reachableDeclarations, overriddenBuiltin, signatureByDescriptor, overriddenBuiltinSignature)
|
||||||
&& methodItself != overriddenBuiltinSignature
|
&& methodItself != overriddenBuiltinSignature
|
||||||
|
|
||||||
val specialBridge = if (needGenerateSpecialBridge)
|
val specialBridge = if (needGenerateSpecialBridge)
|
||||||
@@ -107,15 +108,21 @@ private fun findSuperImplementationForStubDelegation(function: FunctionDescripto
|
|||||||
private fun findAllReachableDeclarations(functionDescriptor: FunctionDescriptor): MutableSet<FunctionDescriptor> =
|
private fun findAllReachableDeclarations(functionDescriptor: FunctionDescriptor): MutableSet<FunctionDescriptor> =
|
||||||
findAllReachableDeclarations(DescriptorBasedFunctionHandle(functionDescriptor)).map { it.descriptor }.toMutableSet()
|
findAllReachableDeclarations(DescriptorBasedFunctionHandle(functionDescriptor)).map { it.descriptor }.toMutableSet()
|
||||||
|
|
||||||
private fun needGenerateSpecialBridge(
|
private fun <Signature> needGenerateSpecialBridge(
|
||||||
functionDescriptor: FunctionDescriptor,
|
functionDescriptor: FunctionDescriptor,
|
||||||
reachableDeclarations: Collection<FunctionDescriptor>,
|
reachableDeclarations: Collection<FunctionDescriptor>,
|
||||||
specialCallableDescriptor: CallableMemberDescriptor
|
specialCallableDescriptor: CallableMemberDescriptor,
|
||||||
|
signatureByDescriptor: (FunctionDescriptor) -> Signature,
|
||||||
|
overriddenBuiltinSignature: Signature
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val classDescriptor = functionDescriptor.containingDeclaration as ClassDescriptor
|
val classDescriptor = functionDescriptor.containingDeclaration as ClassDescriptor
|
||||||
return !classDescriptor.hasRealKotlinSuperClassWithOverrideOf(specialCallableDescriptor)
|
return !classDescriptor.hasRealKotlinSuperClassWithOverrideOf(specialCallableDescriptor)
|
||||||
&& specialCallableDescriptor.modality != Modality.FINAL
|
&& specialCallableDescriptor.modality != Modality.FINAL
|
||||||
&& reachableDeclarations.none { it.containingDeclaration is JavaClassDescriptor && it.modality == Modality.FINAL }
|
&& reachableDeclarations.none {
|
||||||
|
it.containingDeclaration is JavaClassDescriptor
|
||||||
|
&& it.modality == Modality.FINAL
|
||||||
|
&& signatureByDescriptor(it) == overriddenBuiltinSignature
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun isValueArgumentForCallToMethodWithTypeCheckBarrier(
|
public fun isValueArgumentForCallToMethodWithTypeCheckBarrier(
|
||||||
|
|||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
interface Container {
|
||||||
|
fun removeAt(x: Int): String
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ContainerImpl : Container {
|
||||||
|
override fun removeAt(x: Int) = "abc"
|
||||||
|
}
|
||||||
|
|
||||||
|
class A : ContainerImpl(), MutableList<String> {
|
||||||
|
override fun isEmpty(): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val size: Int
|
||||||
|
get() = throw UnsupportedOperationException()
|
||||||
|
|
||||||
|
override fun contains(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun containsAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun get(index: Int): String {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun indexOf(element: String): Int {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun lastIndexOf(element: String): Int {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addAll(index: Int, elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun retainAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clear() {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun set(index: Int, element: String): String {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(index: Int, element: String) {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listIterator(): MutableListIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listIterator(index: Int): MutableListIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun iterator(): MutableIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A()
|
||||||
|
if (a.removeAt(0) != "abc") return "fail 1"
|
||||||
|
|
||||||
|
val l: MutableList<String> = a
|
||||||
|
if (l.removeAt(0) != "abc") return "fail 2"
|
||||||
|
|
||||||
|
val anyList: MutableList<Any?> = a as MutableList<Any?>
|
||||||
|
if (anyList.removeAt(0) != "abc") return "fail 3"
|
||||||
|
|
||||||
|
val container: Container = a
|
||||||
|
if (container.removeAt(0) != "abc") return "fail 4"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class J implements Container {
|
||||||
|
final public String removeAt(int index) { return "abc"; }
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
interface Container {
|
||||||
|
fun removeAt(x: Int): String
|
||||||
|
}
|
||||||
|
|
||||||
|
class A : J(), MutableList<String> {
|
||||||
|
override fun isEmpty(): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val size: Int
|
||||||
|
get() = throw UnsupportedOperationException()
|
||||||
|
|
||||||
|
override fun contains(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun containsAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun get(index: Int): String {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun indexOf(element: String): Int {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun lastIndexOf(element: String): Int {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove(element: String): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addAll(index: Int, elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun retainAll(elements: Collection<String>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clear() {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun set(index: Int, element: String): String {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(index: Int, element: String) {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listIterator(): MutableListIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listIterator(index: Int): MutableListIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun iterator(): MutableIterator<String> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A()
|
||||||
|
if (a.removeAt(0) != "abc") return "fail 1"
|
||||||
|
|
||||||
|
val l: MutableList<String> = a
|
||||||
|
if (l.removeAt(0) != "abc") return "fail 2"
|
||||||
|
|
||||||
|
val anyList: MutableList<Any?> = a as MutableList<Any?>
|
||||||
|
if (anyList.removeAt(0) != "abc") return "fail 3"
|
||||||
|
|
||||||
|
val container: Container = a
|
||||||
|
if (container.removeAt(0) != "abc") return "fail 4"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class J implements Sized {
|
||||||
|
final public int getSize() { return 123; }
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
interface Sized {
|
||||||
|
val size: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
class A<T> : J(), Collection<T> {
|
||||||
|
override fun isEmpty(): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun contains(element: T): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun iterator(): Iterator<T> {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun containsAll(elements: Collection<T>): Boolean {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A<String>()
|
||||||
|
if (a.size != 123) return "fail 1"
|
||||||
|
|
||||||
|
val c: Collection<String> = a
|
||||||
|
if (c.size != 123) return "fail 2"
|
||||||
|
|
||||||
|
val sized: Sized = a
|
||||||
|
if (sized.size != 123) return "fail 3"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -922,6 +922,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irrelevantRemoveAtOverride.kt")
|
||||||
|
public void testIrrelevantRemoveAtOverride() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinsProperties/irrelevantRemoveAtOverride.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("maps.kt")
|
@TestMetadata("maps.kt")
|
||||||
public void testMaps() throws Exception {
|
public void testMaps() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinsProperties/maps.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinsProperties/maps.kt");
|
||||||
|
|||||||
+12
@@ -197,6 +197,18 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irrelevantRemoveAtOverrideInJava")
|
||||||
|
public void testIrrelevantRemoveAtOverrideInJava() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantRemoveAtOverrideInJava/");
|
||||||
|
doTestWithJava(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irrelevantSizeOverrideInJava")
|
||||||
|
public void testIrrelevantSizeOverrideInJava() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/irrelevantSizeOverrideInJava/");
|
||||||
|
doTestWithJava(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("mutableList")
|
@TestMetadata("mutableList")
|
||||||
public void testMutableList() throws Exception {
|
public void testMutableList() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/mutableList/");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/collections/mutableList/");
|
||||||
|
|||||||
Reference in New Issue
Block a user