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 eef7fc2b983..7c4be7139a7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LabelResolver.kt @@ -59,7 +59,11 @@ object LabelResolver { private fun getLabelForFunctionalExpression(element: KtExpression): Name? { val parent = element.parent - return if (parent is KtLabeledExpression) getLabelNameIfAny(parent) else getCallerName(element) + return when (parent) { + is KtLabeledExpression -> getLabelNameIfAny(parent) + is KtBinaryExpression -> parent.operationReference.getReferencedNameAsName() + else -> getCallerName(element) + } } private fun getExpressionUnderLabel(labeledExpression: KtExpression): KtExpression { diff --git a/compiler/testData/codegen/box/labels/infixCallLabelling.kt b/compiler/testData/codegen/box/labels/infixCallLabelling.kt new file mode 100644 index 00000000000..720f0cf5f70 --- /dev/null +++ b/compiler/testData/codegen/box/labels/infixCallLabelling.kt @@ -0,0 +1,24 @@ +fun test(x: Int): Int { + x myMap { + return@myMap + } + + return 0 +} + +fun myMap(x: Int): Int { + x myMap { + return@myMap + } + + return 0 +} + +infix fun Int.myMap(x: () -> Unit) {} + +fun box(): String { + test(0) + myMap(0) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.kt b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.kt new file mode 100644 index 00000000000..00a6f519178 --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.kt @@ -0,0 +1,17 @@ +fun test(x: List): Int { + x myMap { + return@myMap + } + + return 0 +} + +fun myMap(x: List): Int { + x myMap { + return@myMap + } + + return 0 +} + +infix fun List.myMap(x: () -> Unit) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.txt b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.txt new file mode 100644 index 00000000000..95061f2b97d --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.txt @@ -0,0 +1,5 @@ +package + +public fun myMap(/*0*/ x: kotlin.collections.List): kotlin.Int +public fun test(/*0*/ x: kotlin.collections.List): kotlin.Int +public infix fun kotlin.collections.List.myMap(/*0*/ x: () -> kotlin.Unit): kotlin.Unit diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 0d28e6ef1ba..71ae06a33b5 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -10070,6 +10070,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("infixCallLabelling.kt") + public void testInfixCallLabelling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/infixCallLabelling.kt"); + doTest(fileName); + } + @TestMetadata("labeledDeclarations.kt") public void testLabeledDeclarations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 19ac0c20da6..38044ca4db2 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12610,6 +12610,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/labels"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("automaticLabelFromInfixOperator.kt") + public void testAutomaticLabelFromInfixOperator() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/automaticLabelFromInfixOperator.kt"); + doTest(fileName); + } + @TestMetadata("kt1703.kt") public void testKt1703() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/labels/kt1703.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index afd5044084d..672d589f456 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10070,6 +10070,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("infixCallLabelling.kt") + public void testInfixCallLabelling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/infixCallLabelling.kt"); + doTest(fileName); + } + @TestMetadata("labeledDeclarations.kt") public void testLabeledDeclarations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index c914e338f5d..e590cd438b0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10070,6 +10070,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("infixCallLabelling.kt") + public void testInfixCallLabelling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/infixCallLabelling.kt"); + doTest(fileName); + } + @TestMetadata("labeledDeclarations.kt") public void testLabeledDeclarations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index e7c2e40d14e..9972d8dbfb0 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -11601,6 +11601,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("infixCallLabelling.kt") + public void testInfixCallLabelling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/infixCallLabelling.kt"); + doTest(fileName); + } + @TestMetadata("labeledDeclarations.kt") public void testLabeledDeclarations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/labels/labeledDeclarations.kt");