diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.java index 5b50c84e6f8..b47be89b211 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.java @@ -65,6 +65,11 @@ public class LabelResolver { if (element instanceof JetFunctionLiteralExpression) { return getCallerName((JetFunctionLiteralExpression) element); } + if (element instanceof JetNamedFunction) { + Name name = ((JetNamedFunction) element).getNameAsName(); + if (name != null) return name; + return getCallerName((JetNamedFunction) element); + } return null; } @@ -78,7 +83,7 @@ public class LabelResolver { } @Nullable - private Name getCallerName(@NotNull JetFunctionLiteralExpression expression) { + private Name getCallerName(@NotNull JetExpression expression) { JetCallExpression callExpression = getContainingCallExpression(expression); if (callExpression == null) return null; @@ -92,7 +97,7 @@ public class LabelResolver { } @Nullable - private JetCallExpression getContainingCallExpression(@NotNull JetFunctionLiteralExpression expression) { + private JetCallExpression getContainingCallExpression(@NotNull JetExpression expression) { PsiElement parent = expression.getParent(); if (parent instanceof JetFunctionLiteralArgument) { // f {} @@ -103,7 +108,7 @@ public class LabelResolver { } if (parent instanceof JetValueArgument) { - // f ({}) or f(p = {}) + // f ({}) or f(p = {}) or f (fun () {}) JetValueArgument argument = (JetValueArgument) parent; PsiElement argList = argument.getParent(); if (argList == null) return null; diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt new file mode 100644 index 00000000000..616d199753d --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE + +fun Iterable.map(transform: (T) -> R): List = null!! + +fun autolabel(l: List) = l.map (fun (i: Int): Int { + return@map 4 +}) + +fun unresolvedMapLabel(l: List) = l.map (fun test(i: Int): Int { + return@map 4 +}) + +fun labelToFunName(l: List) = l.map (fun test(i: Int): Int { + return@test 4 +}) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.txt b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.txt new file mode 100644 index 00000000000..621934e82e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.txt @@ -0,0 +1,6 @@ +package + +internal fun autolabel(/*0*/ l: kotlin.List): kotlin.List +internal fun labelToFunName(/*0*/ l: kotlin.List): kotlin.List +internal fun unresolvedMapLabel(/*0*/ l: kotlin.List): kotlin.List +internal fun kotlin.Iterable.map(/*0*/ transform: (T) -> R): kotlin.List diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 4091d078792..c119fc45578 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -4634,6 +4634,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/functionAsExpression"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("AutoLabels.kt") + public void testAutoLabels() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt"); + doTest(fileName); + } + @TestMetadata("Common.kt") public void testCommon() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/Common.kt");