From 829a5639f15be63570341caf1ff4240ebda9b147 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 1 Feb 2016 10:55:54 +0300 Subject: [PATCH] Rework error reporting for fake call resolution Move diagnostic creation to one place --- .../DestructuringDeclarationResolver.kt | 6 ----- .../types/expressions/FakeCallResolver.kt | 27 ++++++++++++++----- .../ForLoopConventionsChecker.java | 8 ------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt index e1eee33ec36..2463e68033e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt @@ -64,12 +64,6 @@ class DestructuringDeclarationResolver( context.trace.report(Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.on(reportErrorsOn, componentName, componentType, expectedType)) } } - else if (results.isAmbiguity) { - context.trace.report(Errors.COMPONENT_FUNCTION_AMBIGUITY.on(reportErrorsOn, componentName, results.getResultingCalls())) - } - else { - context.trace.report(Errors.COMPONENT_FUNCTION_MISSING.on(reportErrorsOn, componentName, receiver.getType())) - } if (componentType == null) { componentType = ErrorUtils.createErrorType("$componentName() return type") } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FakeCallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FakeCallResolver.kt index e44b7ac7637..3fd6e67d6b9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FakeCallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FakeCallResolver.kt @@ -100,14 +100,27 @@ class FakeCallResolver( !isFakeKey }, true) } - if (hasUnreportedError && reportErrorsOn != null) { - when (callKind) { - FakeCallKind.ITERATOR -> context.trace.report(Errors.ITERATOR_MISSING.on(reportErrorsOn)) - FakeCallKind.COMPONENT -> - if (receiver != null) { - context.trace.report(Errors.COMPONENT_FUNCTION_MISSING.on(reportErrorsOn, name, receiver.type)) + + val resolutionResults = result.second + if ((!resolutionResults.isSuccess || hasUnreportedError) && reportErrorsOn != null) { + val diagnostic = when (callKind) { + FakeCallKind.ITERATOR -> + when { + resolutionResults.isAmbiguity -> Errors.ITERATOR_AMBIGUITY.on(reportErrorsOn, resolutionResults.resultingCalls) + else -> Errors.ITERATOR_MISSING.on(reportErrorsOn) } - FakeCallKind.OTHER -> {} + FakeCallKind.COMPONENT -> + when { + resolutionResults.isAmbiguity -> Errors.COMPONENT_FUNCTION_AMBIGUITY.on( + reportErrorsOn, name, resolutionResults.resultingCalls) + receiver != null -> Errors.COMPONENT_FUNCTION_MISSING.on(reportErrorsOn, name, receiver.type) + else -> null + } + FakeCallKind.OTHER -> null + } + + if (diagnostic != null) { + context.trace.report(diagnostic) } } return result diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java index 6cb1bac45eb..31f215cee5b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java @@ -90,14 +90,6 @@ public class ForLoopConventionsChecker { NEXT_AMBIGUITY, NEXT_MISSING, NEXT_NONE_APPLICABLE, LOOP_RANGE_NEXT_RESOLVED_CALL); } - else { - if (iteratorResolutionResults.isAmbiguity()) { - context.trace.report(ITERATOR_AMBIGUITY.on(loopRangeExpression, iteratorResolutionResults.getResultingCalls())); - } - else { - context.trace.report(ITERATOR_MISSING.on(loopRangeExpression)); - } - } return null; }