added constraint for package level delegated property
This commit is contained in:
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.DelegatedPropertyUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||
@@ -576,12 +577,14 @@ public class BodyResolver {
|
||||
private void addConstraintForThisValue(ConstraintSystem constraintSystem, FunctionDescriptor resultingDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor thisObject = propertyDescriptor.getExpectedThisObject();
|
||||
if (receiverParameter == null && thisObject == null) return;
|
||||
JetType typeOfThis =
|
||||
receiverParameter != null ? receiverParameter.getType() :
|
||||
thisObject != null ? thisObject.getType() :
|
||||
KotlinBuiltIns.getInstance().getNullableNothingType();
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = resultingDescriptor.getValueParameters();
|
||||
if (valueParameters.isEmpty()) return;
|
||||
ValueParameterDescriptor valueParameterForThis = valueParameters.get(0);
|
||||
JetType typeOfThis = receiverParameter != null ? receiverParameter.getType() : thisObject.getType();
|
||||
constraintSystem.addSubtypeConstraint(typeOfThis, valueParameterForThis.getType(), ConstraintPosition.FROM_COMPLETER);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@ class A1 {
|
||||
var b1: String by getMyProperty1()
|
||||
}
|
||||
|
||||
var c1: String by getMyProperty1<Nothing?, String>()
|
||||
var c1: String by getMyProperty1()
|
||||
var d1: String by MyProperty1()
|
||||
|
||||
fun getMyProperty1<A, B>() = MyProperty1<A, B>()
|
||||
|
||||
@@ -28,6 +29,9 @@ class A2 {
|
||||
var b2: String by getMyProperty2()
|
||||
}
|
||||
|
||||
var c2: String by getMyProperty2()
|
||||
var d2: String by MyProperty2()
|
||||
|
||||
fun getMyProperty2<A>() = MyProperty2<A>()
|
||||
|
||||
class MyProperty2<T> {
|
||||
@@ -49,6 +53,9 @@ class A3 {
|
||||
var b3: String by getMyProperty3()
|
||||
}
|
||||
|
||||
var c3: String by getMyProperty3()
|
||||
var d3: String by MyProperty3()
|
||||
|
||||
fun getMyProperty3<A>() = MyProperty3<A>()
|
||||
|
||||
class MyProperty3<T> {
|
||||
@@ -63,22 +70,5 @@ class MyProperty3<T> {
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
class A4 {
|
||||
val a4: String by MyProperty4()
|
||||
val b4: String by getMyProperty4()
|
||||
}
|
||||
|
||||
fun getMyProperty4<A, B>() = MyProperty4<A, B>()
|
||||
|
||||
class MyProperty4<R, T> {
|
||||
|
||||
public fun get(thisRef: R, desc: PropertyMetadata): T {
|
||||
println("get $thisRef ${desc.name}")
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
fun println(a: Any?) = a
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package foo
|
||||
|
||||
class A1 {
|
||||
val a1: String by MyProperty1()
|
||||
val b1: String by getMyProperty1()
|
||||
}
|
||||
|
||||
val c1: String by getMyProperty1()
|
||||
val d1: String by MyProperty1()
|
||||
|
||||
fun getMyProperty1<A, B>() = MyProperty1<A, B>()
|
||||
|
||||
class MyProperty1<R, T> {
|
||||
|
||||
public fun get(thisRef: R, desc: PropertyMetadata): T {
|
||||
println("get $thisRef ${desc.name}")
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
class A2 {
|
||||
val a2: String by MyProperty2()
|
||||
val b2: String by getMyProperty2()
|
||||
}
|
||||
|
||||
val c2: String by getMyProperty2()
|
||||
val d2: String by MyProperty2()
|
||||
|
||||
fun getMyProperty2<A>() = MyProperty2<A>()
|
||||
|
||||
class MyProperty2<T> {
|
||||
|
||||
public fun get(thisRef: Any?, desc: PropertyMetadata): T {
|
||||
println("get $thisRef ${desc.name}")
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
class A3 {
|
||||
val a3: String by MyProperty3()
|
||||
val b3: String by getMyProperty3()
|
||||
}
|
||||
|
||||
val c3: String by getMyProperty3()
|
||||
val d3: String by MyProperty3()
|
||||
|
||||
fun getMyProperty3<A>() = MyProperty3<A>()
|
||||
|
||||
class MyProperty3<T> {
|
||||
|
||||
public fun get(thisRef: T, desc: PropertyMetadata): String {
|
||||
println("get $thisRef ${desc.name}")
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
fun println(a: Any?) = a
|
||||
@@ -2075,6 +2075,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useExpectedTypeForVal.kt")
|
||||
public void testUseExpectedTypeForVal() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/useExpectedTypeForVal.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
Reference in New Issue
Block a user