FIR: resolve conflicts around SAM calls properly

This commit is contained in:
Mikhail Glukhikh
2022-04-20 22:49:40 +03:00
committed by Space
parent 93dad4837c
commit 7c89f0188a
25 changed files with 107 additions and 204 deletions
@@ -1,30 +0,0 @@
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces
// !CHECK_TYPE
// FILE: Fn.java
public interface Fn<T, R> {
R apply(T t);
}
// FILE: Fn2.java
public interface Fn2<T, R> extends Fn<T, R> {}
// FILE: J.java
public interface J {
String foo(Fn<String, Object> f, Object o);
int foo(Fn<Object, Object> f, String s); // (Any) -> Any <: (String) -> Any <=> String <: Any
String bas(Fn<Object, Object> f, Object o);
int bas(Fn<Object, String> f, String s); // (Any) -> String <: (Any) -> Any <=> String <: Any
String bar(Fn<String, Object> f);
int bar(Fn2<String, Object> f); // Fn2 seems more specific one even function type same
}
// FILE: 1.kt
fun test(j: J) {
j.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>({ <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" }, "") <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
j.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bas<!>({ <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" }, "") <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
j.bar { it checkType { _<String>() }; "" } checkType { _<Int>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces
// !CHECK_TYPE
// FILE: Fn.java
@@ -1,29 +0,0 @@
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces +SamConversionForKotlinFunctions +SamConversionPerArgument
// !CHECK_TYPE
// FILE: Fn.java
public interface Fn<T, R> {
R apply(T t);
}
// FILE: Fn2.java
public interface Fn2<T, R> extends Fn<T, R> {}
// FILE: 1.kt
interface K {
fun foo(f: Fn<String, Any>): String
fun foo(f: Fn<Any, Any>): Int
fun bas(f: Fn<Any, Any>): String
fun bas(f: Fn<Any, String>): Int
fun bar(f: Fn<String, Any>): String
fun bar(f: Fn2<String, Any>): Int
}
fun test(k: K) {
k.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> { <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" } <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
k.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bas<!> { <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any?>() }; "" } <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
k.bar { it checkType { _<String>() }; "" } checkType { _<Int>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces +SamConversionForKotlinFunctions +SamConversionPerArgument
// !CHECK_TYPE
// FILE: Fn.java