[FIR] Handle receiver types of extension methods when computing maximally specific types.

Test case (from testPrimitiveReceiver):

fun Short.foo() = 3
fun Int.foo() = 4

1::foo
This commit is contained in:
Juan Chen
2020-04-13 15:35:08 -07:00
committed by Dmitriy Novozhilov
parent f7dc06a772
commit a1e0e8b0e7
10 changed files with 15 additions and 41 deletions
@@ -6,14 +6,14 @@ fun IB.extFun(x: IA) {}
fun test() {
val extFun1 = IA::extFun
val extFun2 = IB::extFun
val extFun2 = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
}
fun testWithExpectedType() {
// NB: should be resolved to kotlin/FunctionX, not kotlin/reflect/FunctionX
val extFun_AB_A: IA.(IB) -> Unit = IA::extFun
val extFun_AA_B: IA.(IA) -> Unit = IB::extFun
val extFun_AA_B: IA.(IA) -> Unit = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
val extFun_BB_A: IB.(IB) -> Unit = IA::extFun
val extFun_BA_B: IB.(IA) -> Unit = IB::extFun
val extFun_BB_B: IB.(IB) -> Unit = IB::extFun
val extFun_BB_B: IB.(IB) -> Unit = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
}
@@ -9,12 +9,12 @@ FILE: moreSpecificAmbiguousExtensions.kt
}
public final fun test(): R|kotlin/Unit| {
lval extFun1: R|kotlin/reflect/KFunction2<IA, IB, kotlin/Unit>| = Q|IA|::R|/extFun|
lval extFun2: R|kotlin/reflect/KFunction2<IB, IB, kotlin/Unit>| = Q|IB|::R|/extFun|
lval extFun2: <ERROR TYPE REF: No result type for initializer> = Q|IB|::<Unresolved reference: extFun>#
}
public final fun testWithExpectedType(): R|kotlin/Unit| {
lval extFun_AB_A: R|IA.(IB) -> kotlin/Unit| = Q|IA|::R|/extFun|
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::R|/extFun|
lval extFun_AA_B: R|IA.(IA) -> kotlin/Unit| = Q|IB|::<Unresolved reference: extFun>#
lval extFun_BB_A: R|IB.(IB) -> kotlin/Unit| = Q|IA|::R|/extFun|
lval extFun_BA_B: R|IB.(IA) -> kotlin/Unit| = Q|IB|::R|/extFun|
lval extFun_BB_B: R|IB.(IB) -> kotlin/Unit| = Q|IB|::R|/extFun|
lval extFun_BB_B: R|IB.(IB) -> kotlin/Unit| = Q|IB|::<Unresolved reference: extFun>#
}
@@ -163,9 +163,9 @@ abstract class AbstractConeCallConflictResolver(
call: Candidate,
function: FirFunction<*>
): List<ConeKotlinType> {
return (call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType }
?: (listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) +
call.argumentMapping?.map { it.value.argumentType() }.orEmpty()))
return listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) +
(call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType }
?: call.argumentMapping?.map { it.value.argumentType() }.orEmpty())
}
private fun createFlatSignature(call: Candidate, klass: FirClass<*>): FlatSignature<Candidate> {
@@ -1,5 +1,4 @@
// !LANGUAGE: +NewInference
// IGNORE_BACKEND_FIR: JVM_IR
interface JsonParser
interface JsonCodingParser : JsonParser
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
open class A
class B: A()
fun A.foo() {}
fun B.foo() {} // more specific
fun bar(a: Any) {}
fun bar(a: Int) {} // more specific
fun test() {
<!UNRESOLVED_REFERENCE!>B::foo<!>
::bar
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
open class A
@@ -9,13 +9,13 @@ fun IB.extFun(x: IA) {}
fun test() {
val extFun1 = IA::extFun
val extFun2 = IB::extFun
val extFun2 = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
}
fun testWithExpectedType() {
val extFun_AB_A: IA.(IB) -> Unit = IA::extFun
val extFun_AA_B: IA.(IA) -> Unit = IB::extFun
val extFun_AA_B: IA.(IA) -> Unit = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
val extFun_BB_A: IB.(IB) -> Unit = IA::extFun
val extFun_BA_B: IB.(IA) -> Unit = IB::extFun
val extFun_BB_B: IB.(IB) -> Unit = IB::extFun
val extFun_BB_B: IB.(IB) -> Unit = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
}
@@ -1,12 +0,0 @@
// !CHECK_TYPE
interface IA
interface IB : IA
fun IA.extFun() {}
fun IB.extFun() {}
fun test() {
val extFun = <!UNRESOLVED_REFERENCE!>IB::extFun<!>
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><IB.() -> Unit>(extFun)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface IA
@@ -20,7 +20,7 @@ fun fas() {}
fun fas(i: Int = 1) {}
fun test() {
<!UNRESOLVED_REFERENCE!>B::foo<!> // todo KT-9601 Chose maximally specific function in callable reference
B::foo // todo KT-9601 Chose maximally specific function in callable reference
B::bar checkType { _<KFunction1<B, Unit>>() }