do not add NO_EXPECTED_TYPE as a subtype constraint to constraint system
fixed exception from EA
This commit is contained in:
+10
-2
@@ -53,6 +53,7 @@ import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression;
|
|||||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createSimpleName;
|
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createSimpleName;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||||
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.createFakeExpressionOfType;
|
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.createFakeExpressionOfType;
|
||||||
|
|
||||||
public class DelegatedPropertyResolver {
|
public class DelegatedPropertyResolver {
|
||||||
@@ -270,6 +271,11 @@ public class DelegatedPropertyResolver {
|
|||||||
}
|
}
|
||||||
if (!propertyDescriptor.isVar()) return;
|
if (!propertyDescriptor.isVar()) return;
|
||||||
|
|
||||||
|
// For the case: 'val v by d' (no declared type).
|
||||||
|
// When we add a constraint for 'set' method for delegated expression 'd' we use a type of the declared variable 'v'.
|
||||||
|
// But if the type isn't known yet, the constraint shouldn't be added (we try to infer the type of 'v' here as well).
|
||||||
|
if (propertyDescriptor.getReturnType() instanceof DeferredType) return;
|
||||||
|
|
||||||
OverloadResolutionResults<FunctionDescriptor> setMethodResults =
|
OverloadResolutionResults<FunctionDescriptor> setMethodResults =
|
||||||
getDelegatedPropertyConventionMethod(
|
getDelegatedPropertyConventionMethod(
|
||||||
propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, false);
|
propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, false);
|
||||||
@@ -280,8 +286,10 @@ public class DelegatedPropertyResolver {
|
|||||||
if (valueParameters.size() == 3) {
|
if (valueParameters.size() == 3) {
|
||||||
ValueParameterDescriptor valueParameterForThis = valueParameters.get(2);
|
ValueParameterDescriptor valueParameterForThis = valueParameters.get(2);
|
||||||
|
|
||||||
constraintSystem
|
if (!noExpectedType(expectedType)) {
|
||||||
.addSubtypeConstraint(expectedType, valueParameterForThis.getType(), ConstraintPosition.FROM_COMPLETER);
|
constraintSystem.addSubtypeConstraint(
|
||||||
|
expectedType, valueParameterForThis.getType(), ConstraintPosition.FROM_COMPLETER);
|
||||||
|
}
|
||||||
addConstraintForThisValue(constraintSystem, descriptor);
|
addConstraintForThisValue(constraintSystem, descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
class A {
|
||||||
|
var a by <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty<!>()
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyProperty<T, R> {
|
||||||
|
|
||||||
|
public fun get(thisRef: R, desc: PropertyMetadata): T {
|
||||||
|
throw Exception("$thisRef $desc")
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun set(thisRef: R, desc: PropertyMetadata, t: T) {
|
||||||
|
throw Exception("$thisRef $desc $t")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
var a by MyProperty()
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyProperty<T> {
|
||||||
|
fun get(t: T, p: PropertyMetadata): Int = 42
|
||||||
|
fun set(t: T, p: PropertyMetadata, i: Int) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal final class A {
|
||||||
|
/*primary*/ public constructor A()
|
||||||
|
internal final var a: jet.Int
|
||||||
|
internal final fun <get-a>(): jet.Int
|
||||||
|
internal final fun <set-a>(/*0*/ <set-?>: jet.Int): jet.Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class MyProperty</*0*/ T> {
|
||||||
|
/*primary*/ public constructor MyProperty</*0*/ T>()
|
||||||
|
internal final fun get(/*0*/ t: T, /*1*/ p: jet.PropertyMetadata): jet.Int
|
||||||
|
internal final fun set(/*0*/ t: T, /*1*/ p: jet.PropertyMetadata, /*2*/ i: jet.Int): jet.Unit
|
||||||
|
}
|
||||||
@@ -2444,6 +2444,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt");
|
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noExpectedTypeForSupertypeConstraint.kt")
|
||||||
|
public void testNoExpectedTypeForSupertypeConstraint() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("useCompleterWithoutExpectedType.kt")
|
@TestMetadata("useCompleterWithoutExpectedType.kt")
|
||||||
public void testUseCompleterWithoutExpectedType() throws Exception {
|
public void testUseCompleterWithoutExpectedType() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.kt");
|
doTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.kt");
|
||||||
|
|||||||
+5
@@ -816,6 +816,11 @@ public class DescriptorSerializationTestGenerated extends AbstractDescriptorSeri
|
|||||||
doTest("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
doTest("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("VarWithDelegated.kt")
|
||||||
|
public void testVarWithDelegated() throws Exception {
|
||||||
|
doTest("compiler/testData/loadKotlin/prop/VarWithDelegated.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
||||||
public static class DefaultAccessors extends AbstractDescriptorSerializationTest {
|
public static class DefaultAccessors extends AbstractDescriptorSerializationTest {
|
||||||
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
||||||
|
|||||||
@@ -1054,6 +1054,11 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
|||||||
doTestWithAccessors("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
doTestWithAccessors("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("VarWithDelegated.kt")
|
||||||
|
public void testVarWithDelegated() throws Exception {
|
||||||
|
doTestWithAccessors("compiler/testData/loadKotlin/prop/VarWithDelegated.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
||||||
public static class DefaultAccessors extends AbstractLoadCompiledKotlinTest {
|
public static class DefaultAccessors extends AbstractLoadCompiledKotlinTest {
|
||||||
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
||||||
|
|||||||
+5
@@ -1056,6 +1056,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("VarWithDelegated.kt")
|
||||||
|
public void testVarWithDelegated() throws Exception {
|
||||||
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/prop/VarWithDelegated.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
@TestMetadata("compiler/testData/loadKotlin/prop/defaultAccessors")
|
||||||
public static class DefaultAccessors extends AbstractLazyResolveNamespaceComparingTest {
|
public static class DefaultAccessors extends AbstractLazyResolveNamespaceComparingTest {
|
||||||
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
public void testAllFilesPresentInDefaultAccessors() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user