KT-9601, KT-10103:

Chose maximally specific function in callable reference
 #KT-9601 Fixed
 #KT-10103 Fixed
This commit is contained in:
Dmitry Petrov
2015-11-24 19:23:15 +03:00
parent 67dd97b918
commit 9ccb1fd506
16 changed files with 203 additions and 30 deletions
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun fun1() {}
fun fun1(x: Int) {}
val ref1 = ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>fun1<!>
fun fun2(vararg x: Int) {}
fun fun2(x: Int) {}
val ref2 = ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>fun2<!>
fun fun3(x0: Int, vararg xs: Int) {}
fun fun3(x0: String, vararg xs: String) {}
val ref3 = ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>fun3<!>
@@ -0,0 +1,11 @@
package
public val ref1: [ERROR : Type for ::fun1]
public val ref2: [ERROR : Type for ::fun2]
public val ref3: [ERROR : Type for ::fun3]
public fun fun1(): kotlin.Unit
public fun fun1(/*0*/ x: kotlin.Int): kotlin.Unit
public fun fun2(/*0*/ x: kotlin.Int): kotlin.Unit
public fun fun2(/*0*/ vararg x: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit
public fun fun3(/*0*/ x0: kotlin.Int, /*1*/ vararg xs: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit
public fun fun3(/*0*/ x0: kotlin.String, /*1*/ vararg xs: kotlin.String /*kotlin.Array<out kotlin.String>*/): kotlin.Unit
@@ -0,0 +1,15 @@
// !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() {
B::foo
::bar
}
@@ -0,0 +1,21 @@
package
public fun bar(/*0*/ a: kotlin.Any): kotlin.Unit
public fun bar(/*0*/ a: kotlin.Int): kotlin.Unit
public fun test(): kotlin.Unit
public fun A.foo(): kotlin.Unit
public fun B.foo(): kotlin.Unit
public open class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B : A {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,21 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
interface IA
interface IB : IA
fun IA.extFun(x: IB) {}
fun IB.extFun(x: IA) {}
fun test() {
val extFun1 = IA::extFun
val extFun2 = IB::<!OVERLOAD_RESOLUTION_AMBIGUITY!>extFun<!>
}
fun testWithExpectedType() {
val extFun_AB_A: IA.(IB) -> Unit = IA::extFun
val extFun_AA_B: IA.(IA) -> Unit = IB::<!NONE_APPLICABLE!>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::<!OVERLOAD_RESOLUTION_AMBIGUITY!>extFun<!>
}
@@ -0,0 +1,18 @@
package
public fun test(): kotlin.Unit
public fun testWithExpectedType(): kotlin.Unit
public fun IA.extFun(/*0*/ x: IB): kotlin.Unit
public fun IB.extFun(/*0*/ x: IA): kotlin.Unit
public interface IA {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface IB : IA {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,12 @@
// !CHECK_TYPE
interface IA
interface IB : IA
fun IA.extFun() {}
fun IB.extFun() {}
fun test() {
val extFun = IB::extFun
checkSubtype<IB.() -> Unit>(extFun)
}
@@ -0,0 +1,17 @@
package
public fun test(): kotlin.Unit
public fun IA.extFun(): kotlin.Unit
public fun IB.extFun(): kotlin.Unit
public interface IA {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface IB : IA {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -20,7 +20,7 @@ fun fas() {}
fun fas(i: Int = 1) {}
fun test() {
B::<!OVERLOAD_RESOLUTION_AMBIGUITY!>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>>() }
@@ -11,6 +11,6 @@ class B: A() {
}
fun test() {
B::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>
B::<!OVERLOAD_RESOLUTION_AMBIGUITY!>fas<!>
B::foo
B::fas
}