mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-11 15:53:46 +00:00
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
This commit is contained in:
22
compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFun.kt
vendored
Normal file
22
compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFun.kt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(): String = "foo1"
|
||||
fun foo(i: Int): String = "foo2"
|
||||
|
||||
val f1: () -> String = ::foo
|
||||
val f2: (Int) -> String = ::foo
|
||||
|
||||
fun foo1() {}
|
||||
fun foo2(i: Int) {}
|
||||
|
||||
fun bar(f: () -> Unit): String = "bar1"
|
||||
fun bar(f: (Int) -> Unit): String = "bar2"
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("foo1", f1())
|
||||
assertEquals("foo2", f2(0))
|
||||
assertEquals("bar1", bar(::foo1))
|
||||
assertEquals("bar2", bar(::foo2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
19
compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFunVsVal.kt
vendored
Normal file
19
compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFunVsVal.kt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
val x = 1
|
||||
fun x(): String = "OK"
|
||||
}
|
||||
|
||||
val f1: KProperty1<A, Int> = A::x
|
||||
val f2: (A) -> String = A::x
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
assertEquals(1, f1.get(a))
|
||||
assertEquals("OK", f2(a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user