diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java index c0682d709eb..03940e44b03 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java @@ -184,7 +184,7 @@ public class DelegatedPropertyResolver { if (trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor) != null) return; OverloadResolutionResults functionResults = getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, delegateType, trace, scope, isGet); + propertyDescriptor, delegateExpression, delegateType, trace, scope, isGet, true); Call call = trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor); assert call != null : "'getDelegatedPropertyConventionMethod' didn't record a call"; @@ -218,14 +218,18 @@ public class DelegatedPropertyResolver { @NotNull JetType delegateType, @NotNull BindingTrace trace, @NotNull JetScope scope, - boolean isGet + boolean isGet, + boolean isComplete ) { PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter(); assert accessor != null : "Delegated property should have getter/setter " + propertyDescriptor + " " + delegateExpression.getText(); + JetType expectedType = isComplete && isGet && !(propertyDescriptor.getType() instanceof DeferredType) + ? propertyDescriptor.getType() : TypeUtils.NO_EXPECTED_TYPE; + ExpressionTypingContext context = ExpressionTypingContext.newContext( expressionTypingServices, trace, scope, - DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE); + DataFlowInfo.EMPTY, expectedType); boolean hasThis = propertyDescriptor.getExtensionReceiverParameter() != null || propertyDescriptor.getDispatchReceiverParameter() != null; @@ -318,7 +322,9 @@ public class DelegatedPropertyResolver { TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods"); OverloadResolutionResults getMethodResults = getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, true); + propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, + true, false + ); if (conventionMethodFound(getMethodResults)) { FunctionDescriptor descriptor = getMethodResults.getResultingDescriptor(); @@ -335,9 +341,11 @@ public class DelegatedPropertyResolver { // 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 setMethodResults = - getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, false); + OverloadResolutionResults + setMethodResults = getDelegatedPropertyConventionMethod( + propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, + false, false + ); if (conventionMethodFound(setMethodResults)) { FunctionDescriptor descriptor = setMethodResults.getResultingDescriptor(); diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt new file mode 100644 index 00000000000..6a1de8d4a40 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A() { + fun get(t: Any?, p: PropertyMetadata): T = null!! + fun set(t: Any?, p: PropertyMetadata, x: T) = Unit +} + +var a1: Int by A() +var a2: Int by A() + +class B() { + fun get(t: Any?, p: PropertyMetadata): T = null!! + fun set(t: Any?, p: PropertyMetadata, x: R) = Unit +} + +var b1: Int by B() +var b2: Int by B() + +class C() { + fun get(t: Any?, p: PropertyMetadata): R = null!! + fun set(t: Any?, p: PropertyMetadata, x: T) = Unit +} + +var c1: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.txt new file mode 100644 index 00000000000..a568b5c8a64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.txt @@ -0,0 +1,35 @@ +package + +internal var a1: kotlin.Int +internal var a2: kotlin.Int +internal var b1: kotlin.Int +internal var b2: kotlin.Int +internal var c1: kotlin.Int +internal var c2: kotlin.Int + +internal final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: R): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): R + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt new file mode 100644 index 00000000000..e8230477cec --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +var a: Int by A() +var a1 by A() + +var b: Int by B() + +val cObj = C() +var c: String by cObj + +class A { + fun get(t: Any?, p: PropertyMetadata): T = null!! + fun set(t: Any?, p: PropertyMetadata, x: T) = Unit +} + +class B + +fun B.get(t: Any?, p: PropertyMetadata): T = null!! +fun B.set(t: Any?, p: PropertyMetadata, x: T) = Unit + +class C + +inline fun C.get(t: Any?, p: PropertyMetadata): T = null!! +inline fun C.set(t: Any?, p: PropertyMetadata, x: T) = Unit diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.txt new file mode 100644 index 00000000000..eb4b3c11525 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.txt @@ -0,0 +1,34 @@ +package + +internal var a: kotlin.Int +internal var a1: [ERROR : Type from delegate] +internal var b: kotlin.Int +internal var c: kotlin.String +internal val cObj: C +internal fun B.get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): T +kotlin.inline() internal fun C.get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): T +internal fun B.set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: T): kotlin.Unit +kotlin.inline() internal fun C.set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: T): kotlin.Unit + +internal final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ x: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class B { + public constructor B() + 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 +} + +internal final class C { + public constructor C() + 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 +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 7e7523264f9..d6aad1e23db 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -3147,6 +3147,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("genericMethodInGenericClass.kt") + public void testGenericMethodInGenericClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt"); + doTest(fileName); + } + + @TestMetadata("genericMethods.kt") + public void testGenericMethods() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt"); + doTest(fileName); + } + @TestMetadata("labeledDelegatedExpression.kt") public void testLabeledDelegatedExpression() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.kt");