KT-22274 report warning on labels that can't be referenced
Labels are meaningful only if they can be referenced by 'break', 'continue', or 'return' expressions.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
@Target(AnnotationTarget.EXPRESSION)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Ann
|
||||
|
||||
fun testLambdaLabel() = l@ { 42 }
|
||||
|
||||
fun testAnonymousFunctionLabel() = l@ fun() {}
|
||||
|
||||
fun testAnnotatedLambdaLabel() = lambda@ @Ann {}
|
||||
|
||||
fun testParenthesizedLambdaLabel() = lambda@ ( {} )
|
||||
|
||||
fun testLabelBoundToInvokeOperatorExpression() = <!REDUNDANT_LABEL_WARNING!>l@<!> { 42 }()
|
||||
|
||||
fun testLabelBoundToLambda() = (l@ { 42 })()
|
||||
|
||||
fun testWhileLoopLabel() {
|
||||
L@ while (true) {}
|
||||
}
|
||||
|
||||
fun testDoWhileLoopLabel() {
|
||||
L@ do {} while (true)
|
||||
}
|
||||
|
||||
fun testForLoopLabel(xs: List<Any>) {
|
||||
L@ for (x in xs) {}
|
||||
}
|
||||
|
||||
fun testValLabel() {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = {}
|
||||
fn()
|
||||
}
|
||||
|
||||
fun testHighOrderFunctionCallLabel() {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> run {}
|
||||
}
|
||||
|
||||
fun testAnonymousObjectLabel() =
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> object {}
|
||||
Reference in New Issue
Block a user