Files
kotlin/compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.kt
Dmitry Petrov 6437a4bdc6 Support overload ambiguity resolution for callable references by expected type.
Resolve callable references taking into account expected callable types.

This affects call resolution procedure (resolve 'foo' in for 'foo(::bar)') similar to the approach used for function literals:

* During "shape arguments" phase of call resolution, callable references are resolved in independent context without expected type. If the callable reference is ambiguous, its shape type is a function placeholder type without parameter types and return type information. Otherwise, it is a reflection type for the resolved function or property. Upper-level call is resolved without taking into account ambiguous callable references.

* During "complete call" phase of call resolution, resolve callable reference arguments to actual descriptors (if possible), and update constraint system for the given call accordingly.

 #KT-6982 Fixed
 #KT-5780 Fixed
2015-07-21 18:33:15 +03:00

29 lines
564 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.*
fun <T> ofType(x: T): T = x
class A {
val foo: Int = 0
fun foo() {}
fun bar() {}
val bar: Int = 0
}
fun A.foo(): String = "A"
val x0 = A::foo // function A::foo wins by default
val userOfX0 = x0(A())
val x1 = ofType<(A) -> Unit>(A::foo)
val x2 = ofType<KProperty1<A, Int>>(A::foo)
val x3: KProperty1<A, Int> = A::foo
val x4: (A) -> String = A::foo
val y0 = A::bar
val y1 = ofType<(A) -> Unit>(A::bar)
val y2 = ofType<KProperty1<A, Int>>(A::bar)
val y3: KProperty1<A, Int> = A::bar