diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b5e0641fa11..bac4ec139b9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -731,7 +731,6 @@ public interface Errors { DiagnosticFactory0 BREAK_OR_CONTINUE_IN_WHEN = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 NOT_A_LOOP_LABEL = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR); // Control flow / Data flow diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index da62bab5060..e64cbf42cd4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -555,7 +555,6 @@ public class DefaultErrorMessages { MAP.put(BREAK_OR_CONTINUE_IN_WHEN, "'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop"); MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function or a class boundary"); MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING); - MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING); MAP.put(ANONYMOUS_INITIALIZER_IN_INTERFACE, "Anonymous initializers are not allowed in interfaces"); MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 2bd48ac98d4..930580fd640 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -623,9 +623,6 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE); } } - else { - context.trace.report(NOT_A_RETURN_LABEL.on(expression, expression.getLabelName())); - } } if (returnedExpression != null) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt index a00bc6ee41d..efeefd14a64 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt @@ -106,32 +106,10 @@ object LabelResolver { val labelName = expression.getLabelNameAsName() if (labelElement == null || labelName == null) return null - val element = resolveNamedLabel(labelName, labelElement, context.trace) - if (element != null) return element - - val declarationsByLabel = context.scope.getDeclarationsByLabel(labelName) - when (declarationsByLabel.size) { - 0 -> { - context.trace.report(UNRESOLVED_REFERENCE.on(labelElement, labelElement)) - return null - } - 1 -> { - val declarationDescriptor = declarationsByLabel.single() - if (declarationDescriptor is FunctionDescriptor || declarationDescriptor is ClassDescriptor) { - val declarationElement = DescriptorToSourceUtils.descriptorToDeclaration(declarationDescriptor) - if (declarationElement is KtElement) { - context.trace.record(LABEL_TARGET, labelElement, declarationElement) - return declarationElement - } - } - } - else -> { - BindingContextUtils.reportAmbiguousLabel(context.trace, labelElement, declarationsByLabel) - return null - } + return resolveNamedLabel(labelName, labelElement, context.trace) ?: run { + context.trace.report(UNRESOLVED_REFERENCE.on(labelElement, labelElement)) + null } - - return null } private fun resolveNamedLabel( diff --git a/compiler/testData/diagnostics/tests/Return.kt b/compiler/testData/diagnostics/tests/Return.kt index e540b5071c3..f1b0d7cee9d 100644 --- a/compiler/testData/diagnostics/tests/Return.kt +++ b/compiler/testData/diagnostics/tests/Return.kt @@ -6,10 +6,10 @@ class A { if (1 < 2) return@inner else - return@outer + return@outer } if (1 < 2) - return@A + return@A else if (2 < 3) return@inner return@outer