FIR: Fix ambiguity on Int2IntMap in IC
This commit is contained in:
+6
@@ -2390,6 +2390,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("int2IntMap.kt")
|
||||
public void testInt2IntMap() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Iterator.kt")
|
||||
public void testIterator() throws Exception {
|
||||
|
||||
@@ -66,11 +66,23 @@ class JavaOverrideChecker internal constructor(
|
||||
candidateTypeRef: FirTypeRef,
|
||||
baseTypeRef: FirTypeRef,
|
||||
substitutor: ConeSubstitutor
|
||||
) = isEqualTypes(
|
||||
candidateTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack),
|
||||
baseTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack),
|
||||
substitutor
|
||||
)
|
||||
): Boolean {
|
||||
val candidateType = candidateTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack)
|
||||
val baseType = baseTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack)
|
||||
|
||||
if (candidateType.isPrimitiveInJava() != baseType.isPrimitiveInJava()) return false
|
||||
|
||||
return isEqualTypes(
|
||||
candidateType,
|
||||
baseType,
|
||||
substitutor
|
||||
)
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.isPrimitiveInJava(): Boolean = with(context) {
|
||||
// TODO: Support enhanced type like `@NotNull Integer` that are not nullable, but still aren't primitive
|
||||
!isNullableType() && isPrimitiveOrNullablePrimitive
|
||||
}
|
||||
|
||||
private fun isEqualArrayElementTypeProjections(
|
||||
candidateTypeProjection: ConeTypeProjection,
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
// FILE: Int2IntFunction.java
|
||||
public interface Int2IntFunction {
|
||||
boolean containsKey(int key);
|
||||
|
||||
@Deprecated
|
||||
default boolean containsKey(Object key) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// FILE: Int2IntMap.java
|
||||
public interface Int2IntMap extends Int2IntFunction, java.util.Map<Integer, Integer> {
|
||||
boolean containsKey(int var1);
|
||||
|
||||
@Deprecated
|
||||
default boolean containsKey(Object key) {
|
||||
return Int2IntFunction.super.containsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Int2IntMapImpl.java
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Int2IntMapImpl implements Int2IntMap {
|
||||
@Override
|
||||
public boolean containsKey(int var1) {
|
||||
return var1 == 56;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer put(Integer key, Integer value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer remove(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends Integer, ? extends Integer> m) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> keySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Integer> values() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<Integer, Integer>> entrySet() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FILE: m.kt
|
||||
fun foo(x: Int2IntMap): String {
|
||||
if (!x.containsKey(56)) return "fail 1"
|
||||
if (x.containsKey(239)) return "fail 1"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo(Int2IntMapImpl())
|
||||
}
|
||||
+1
-1
@@ -17,6 +17,6 @@ public class B extends A {
|
||||
|
||||
fun foo(b: B) {
|
||||
// See KT-9182
|
||||
b.foo(1)
|
||||
b.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>(1)
|
||||
b.bar(2.0)
|
||||
}
|
||||
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
// FILE: AbstractSpecializedMap.java
|
||||
public abstract class AbstractSpecializedMap implements java.util.Map<Integer, Double> {
|
||||
public abstract double put(int x, double y);
|
||||
public abstract double remove(int k);
|
||||
public abstract double get(int k);
|
||||
|
||||
public abstract boolean containsKey(int k);
|
||||
public boolean containsKey(Object x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract boolean containsValue(double v);
|
||||
public boolean containsValue(Object x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: SpecializedMap.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SpecializedMap extends AbstractSpecializedMap {
|
||||
public double put(int x, double y) {
|
||||
return 123.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double get(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double put(Integer key, Double value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public double remove(int k) {
|
||||
return 456.0;
|
||||
}
|
||||
|
||||
|
||||
public Double remove(Object ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public double get(int k) {
|
||||
return 789.0;
|
||||
}
|
||||
|
||||
public boolean containsKey(int k) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean containsValue(double v) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends Integer, ? extends Double> m) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Integer> keySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Double> values() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<Integer, Double>> entrySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: SpecializedMap) {
|
||||
x.containsKey(1)
|
||||
x.containsKey(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
|
||||
x.<!OVERLOAD_RESOLUTION_AMBIGUITY!>get<!>(2)
|
||||
x.<!NONE_APPLICABLE!>get<!>(null)
|
||||
|
||||
x.<!OVERLOAD_RESOLUTION_AMBIGUITY!>remove<!>(3)
|
||||
x.<!NONE_APPLICABLE!>remove<!>(null)
|
||||
|
||||
x.put(4, 5.0)
|
||||
x.put(4, null)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: AbstractSpecializedMap.java
|
||||
public abstract class AbstractSpecializedMap implements java.util.Map<Integer, Double> {
|
||||
public abstract double put(int x, double y);
|
||||
|
||||
+6
@@ -2294,6 +2294,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("int2IntMap.kt")
|
||||
public void testInt2IntMap() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Iterator.kt")
|
||||
public void testIterator() throws Exception {
|
||||
|
||||
+6
@@ -2390,6 +2390,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("int2IntMap.kt")
|
||||
public void testInt2IntMap() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("Iterator.kt")
|
||||
public void testIterator() throws Exception {
|
||||
|
||||
+5
@@ -2014,6 +2014,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("int2IntMap.kt")
|
||||
public void testInt2IntMap() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Iterator.kt")
|
||||
public void testIterator() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/Iterator.kt");
|
||||
|
||||
Reference in New Issue
Block a user