Support automatic labeling for infix calls

#KT-8877 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-04-10 17:17:21 +03:00
parent 6a352bccb6
commit 1fbd8f3f53
9 changed files with 81 additions and 1 deletions
@@ -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 {
@@ -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"
}
@@ -0,0 +1,17 @@
fun test(x: List<Int>): Int {
x myMap {
return@myMap
}
return 0
}
fun myMap(x: List<Int>): Int {
x myMap {
return<!LABEL_NAME_CLASH!>@myMap<!>
}
return 0
}
infix fun List<Int>.myMap(<!UNUSED_PARAMETER!>x<!>: () -> Unit) {}
@@ -0,0 +1,5 @@
package
public fun myMap(/*0*/ x: kotlin.collections.List<kotlin.Int>): kotlin.Int
public fun test(/*0*/ x: kotlin.collections.List<kotlin.Int>): kotlin.Int
public infix fun kotlin.collections.List<kotlin.Int>.myMap(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
@@ -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");
@@ -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");
@@ -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");
@@ -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");
@@ -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");