Files
kotlin-fork/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt
T
Tianyu Geng 363b25504d FIR checker: report REDUNDANT_LABEL_WARNING
Since many labels are not present in the FIR tree, this checker is
implemented as a syntax checker. Comparing with FE1.0, this change
reports some REDUNDANT_LABEL_WARNING that FE1.0 has missed, especially
LHS of assignments.
2021-10-25 13:51:01 +03:00

72 lines
1.3 KiB
Kotlin
Vendored

// !LANGUAGE: +RestrictReturnStatementTarget
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann
fun testFunctionName() {
return@testFunctionName
}
fun testHighOrderFunctionName() {
run {
return@run
}
}
fun testLambdaLabel() =
lambda@ {
return@lambda
}
fun testParenthesizedLambdaLabel() =
lambda@ ( {
return@lambda
} )
fun testAnnotatedLambdaLabel() =
lambda@ @Ann {
return@lambda
}
fun testLambdaMultipleLabels1() =
lambda1@ lambda2@ {
<!NOT_A_FUNCTION_LABEL!>return@lambda1<!>
}
fun testLambdaMultipleLabels2() =
lambda1@ lambda2@ {
return@lambda2
}
fun testAnonymousFunctionLabel() =
anonFun@ fun() {
return@anonFun
}
fun testLoopLabelInReturn(xs: List<Int>) {
L@ for (x in xs) {
if (x > 0) <!NOT_A_FUNCTION_LABEL!>return@L<!>
}
}
fun testValLabelInReturn() {
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = { <!NOT_A_FUNCTION_LABEL!>return@L<!> }
fn()
}
fun testHighOrderFunctionCallLabelInReturn() {
<!REDUNDANT_LABEL_WARNING!>L@<!> run {
<!NOT_A_FUNCTION_LABEL!>return@L<!>
}
}
fun testMultipleLabelsWithNestedLambda() {
l1@ l2@{
{
<!NOT_A_FUNCTION_LABEL!>return@l1<!>
}
return@l2
}
}