[FIR] Forbid multiple labels per statement

^KT-53629: Fixed
This commit is contained in:
vladislav.grechko
2024-01-25 17:24:27 +01:00
committed by Space Team
parent cd5b38b958
commit d27adf6677
29 changed files with 201 additions and 34 deletions
@@ -0,0 +1,10 @@
// K2: See KT-65342
fun test() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>a@<!> b@ while(true) {
val f = {
return@a
}
break@b
}
}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// K2: See KT-65342
fun test() {
a@ b@ while(true) {
val f = {
@@ -30,12 +30,12 @@ fun testAnnotatedLambdaLabel() =
}
fun testLambdaMultipleLabels1() =
lambda1@ lambda2@ {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>lambda1@<!> lambda2@ {
<!NOT_A_FUNCTION_LABEL!>return@lambda1<!>
}
fun testLambdaMultipleLabels2() =
lambda1@ lambda2@ {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>lambda1@<!> lambda2@ {
return@lambda2
}
@@ -62,7 +62,7 @@ fun testHighOrderFunctionCallLabelInReturn() {
}
fun testMultipleLabelsWithNestedLambda() {
l1@ l2@{
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l1@<!> l2@{
{
<!NOT_A_FUNCTION_LABEL!>return@l1<!>
}
@@ -30,12 +30,12 @@ fun testAnnotatedLambdaLabel() =
}
fun testLambdaMultipleLabels1() =
lambda1@ lambda2@ {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>lambda1@<!> lambda2@ {
<!NOT_A_FUNCTION_LABEL!>return@lambda1<!>
}
fun testLambdaMultipleLabels2() =
lambda1@ lambda2@ {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>lambda1@<!> lambda2@ {
return@lambda2
}
@@ -62,7 +62,7 @@ fun testHighOrderFunctionCallLabelInReturn() {
}
fun testMultipleLabelsWithNestedLambda() {
l1@ l2@{
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l1@<!> l2@{
{
<!NOT_A_FUNCTION_LABEL!>return@l1<!>
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING -UNDERSCORE_IS_RESERVED
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING -UNDERSCORE_IS_RESERVED -MULTIPLE_LABELS_ARE_FORBIDDEN
// See KT-65337
// !DIAGNOSTICS: -UNRESOLVED_REFERENCE
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING -UNDERSCORE_IS_RESERVED
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING -UNDERSCORE_IS_RESERVED -MULTIPLE_LABELS_ARE_FORBIDDEN
// See KT-65337
// !DIAGNOSTICS: -UNRESOLVED_REFERENCE
@@ -23,5 +23,5 @@ inline fun inlineFunWithInvoke2(s: (p: Int) -> Unit) {
inline fun propagation(s: (p: Int) -> Unit) {
inlineFunWithInvoke((label@ s))
inlineFunWithInvoke((label2@ label@ s))
inlineFunWithInvoke((<!MULTIPLE_LABELS_ARE_FORBIDDEN!>label2@<!> label@ s))
}
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING
fun foo1() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ do {
} while (true)
}
fun foo2() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l4@<!> <!UNDERSCORE_IS_RESERVED!>_<!>@ <!MULTIPLE_LABELS_ARE_FORBIDDEN!>l3@<!> <!UNDERSCORE_IS_RESERVED!>__<!>@ <!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ while (true) {
}
}
fun foo3() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ 42
}
fun foo4() {
l1@ do {
l4@ { false }
} while (true)
}
fun foo5() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ do {
l4@ { false }
} while (true)
}
fun foo6() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ do {
l4@ l3@{ true }
} while (true)
}
fun foo7() {
<!MULTIPLE_LABELS_ARE_FORBIDDEN!>l3@<!> <!MULTIPLE_LABELS_ARE_FORBIDDEN!>l2@<!> l1@ fun bar() {}
}
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -REDUNDANT_LABEL_WARNING
fun foo1() {
l2@ l1@ do {
} while (true)
}
fun foo2() {
l4@ <!UNDERSCORE_IS_RESERVED!>_<!>@ l3@ <!UNDERSCORE_IS_RESERVED!>__<!>@ l2@ l1@ while (true) {
}
}
fun foo3() {
l2@ l1@ 42
}
fun foo4() {
l1@ do {
l4@ { false }
} while (true)
}
fun foo5() {
l2@ l1@ do {
l4@ { false }
} while (true)
}
fun foo6() {
l2@ l1@ do {
l4@ l3@{ true }
} while (true)
}
fun foo7() {
l3@ l2@ l1@ fun bar() {}
}
@@ -1,3 +1,5 @@
// K2: See KT-65342
fun main() {
val a : Int? = null;
var v = 1
@@ -9,7 +11,7 @@ fun main() {
val h1 : String = <!INITIALIZER_TYPE_MISMATCH!>--v<!>;
val i : String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>!true<!>;
val j : String = <!INITIALIZER_TYPE_MISMATCH!>foo@ true<!>;
val k : String = <!INITIALIZER_TYPE_MISMATCH!>foo@ bar@ true<!>;
val k : String = <!MULTIPLE_LABELS_ARE_FORBIDDEN!>foo@<!> bar@ true;
val l : String = <!INITIALIZER_TYPE_MISMATCH!>-1<!>;
val m : String = <!INITIALIZER_TYPE_MISMATCH!>+1<!>;
}
@@ -1,3 +1,5 @@
// K2: See KT-65342
fun main() {
val a : Int? = null;
var v = 1