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:
Dmitry Petrov
2015-07-14 17:53:12 +03:00
parent b3a2ee2148
commit 6437a4bdc6
51 changed files with 1057 additions and 247 deletions
@@ -0,0 +1,8 @@
import kotlin.reflect.KProperty1
fun <T, R> getProperty(x: T, property: KProperty1<T, R>): R =
property.get(x)
class Person(val name: String)
val name1 = getProperty(Person("John Smith"), Person::name)
@@ -0,0 +1,12 @@
package
internal val name1: kotlin.String
internal fun </*0*/ T, /*1*/ R> getProperty(/*0*/ x: T, /*1*/ property: kotlin.reflect.KProperty1<T, R>): R
internal final class Person {
public constructor Person(/*0*/ name: kotlin.String)
internal final val name: kotlin.String
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,19 @@
// FILE: Customer.java
public class Customer {
private String name;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
// FILE: test.kt
val customerName = Customer::name
@@ -0,0 +1,13 @@
package
internal val customerName: kotlin.reflect.KMutableProperty1<Customer, kotlin.String!>
public open class Customer {
public constructor Customer(/*0*/ name: kotlin.String!)
private final var name: kotlin.String!
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open fun setName(/*0*/ name: kotlin.String!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}