From e10f7fb464a0aaa27864799a570691536e5c8eda Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 2 Nov 2015 18:23:18 +0300 Subject: [PATCH] Don't report missing getValue/setValue method error when it's was impossible to finish resolve #KT-9803 Fixed --- .../resolve/DelegatedPropertyResolver.java | 7 ++---- .../inference/genericMethods.kt | 2 +- .../inference/manyIncompleteCandidates.kt | 25 +++++++++++++++++++ .../inference/manyIncompleteCandidates.txt | 20 +++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 +++++ 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.kt create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java index b48260e3795..483b6cbf769 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java @@ -189,13 +189,10 @@ public class DelegatedPropertyResolver { if (!functionResults.isSuccess()) { String expectedFunction = renderCall(call, trace.getBindingContext()); - if (functionResults.isIncomplete()) { - trace.report(DELEGATE_SPECIAL_FUNCTION_MISSING.on(delegateExpression, expectedFunction, delegateType)); - } - else if (functionResults.isSingleResult() || + if (functionResults.isSingleResult() || functionResults.isIncomplete() || functionResults.getResultCode() == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES) { trace.report(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE - .on(delegateExpression, expectedFunction, functionResults.getResultingCalls())); + .on(delegateExpression, expectedFunction, functionResults.getResultingCalls())); } else if (functionResults.isAmbiguity()) { trace.report(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt index bf68999d53a..842bc41c4d6 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt @@ -2,7 +2,7 @@ import kotlin.reflect.KProperty var a: Int by A() -var a1 by A() +var a1 by A() var b: Int by B() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.kt new file mode 100644 index 00000000000..4593f60bf84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.kt @@ -0,0 +1,25 @@ +// FILE: main.kt +package test + +import first.* +import second.* + +val a12 by A() + +// FILE: first.kt +package first + +import kotlin.reflect.KProperty + +class A + +public operator fun A.getValue(thisRef: Any?, property: KProperty<*>): T = null!! + + +// FILE: second.kt +package second + +import first.A +import kotlin.reflect.KProperty + +public operator fun A.getValue(thisRef: Any?, property: KProperty<*>): T = null!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.txt new file mode 100644 index 00000000000..ed1092ec5ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.txt @@ -0,0 +1,20 @@ +package + +package first { + public operator fun first.A.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T + + public final class A { + public constructor A() + 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 + } +} + +package second { + public operator fun first.A.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T +} + +package test { + public val a12: [ERROR : Type from delegate] +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index a7173da77a2..0a8dfe1cb18 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -4589,6 +4589,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("manyIncompleteCandidates.kt") + public void testManyIncompleteCandidates() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.kt"); + doTest(fileName); + } + @TestMetadata("noErrorsForImplicitConstraints.kt") public void testNoErrorsForImplicitConstraints() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt");