Added missing specificity comparator to FIR

This is required to correctly resolve overloading in cases when we
need to find most specific alternative in Java between int and Integer.
This commit is contained in:
Alexander Podkhalyuzin
2020-04-28 17:17:31 +03:00
parent b6b8dd1eab
commit 6372c01e49
14 changed files with 39 additions and 181 deletions
@@ -1,24 +0,0 @@
// JAVAC_EXPECTED_FILE
// FILE: B.java
public interface B<T1, T2> {
double put(int x, double y);
T2 put(T1 x, T2 y);
}
// FILE: A.java
import java.util.HashMap;
public class A extends HashMap<Integer, Double> implements B<Integer, Double> {
public double put(int x, double y) {
return 1.0;
}
@Override
public Double put(Integer key, Double value) {
return super.put(key, value);
}
}
// FILE: main.kt
fun test(){
val o = A()
o.<!AMBIGUITY!>put<!>(1, 2.0)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JAVAC_EXPECTED_FILE
// FILE: B.java
public interface B<T1, T2> {
@@ -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)
x.get(2)
x.get(null)
x.remove(3)
x.remove(null)
x.<!AMBIGUITY!>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);
@@ -1,37 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: p/J.java
package p;
public class J {
public interface A {}
public static A foo(int s);
public interface B {}
public static B foo(Integer s);
public static Integer getInteger();
}
// FILE: k.kt
import p.*
import p.J.*
class C
fun foo(i: Int?) : C = null!!
fun test(i: Int, ni: Int?) {
checkSubtype<C>(foo(2))
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><J.A>(J.<!AMBIGUITY!>foo<!>(2))
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><J.A>(J.<!AMBIGUITY!>foo<!>(i))
checkSubtype<J.B>(J.foo(ni))
checkSubtype<C>(foo(ni))
checkSubtype<J.B>(J.foo(ni))
foo(J.getInteger())
J.<!AMBIGUITY!>foo<!>(J.getInteger())
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: p/J.java