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:
+2
-2
@@ -51,12 +51,12 @@ fun testLoopLabelInReturn(xs: List<Int>) {
|
||||
}
|
||||
|
||||
fun testValLabelInReturn() {
|
||||
L@ val fn = { <!NOT_A_FUNCTION_LABEL!>return@L<!> }
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = { <!NOT_A_FUNCTION_LABEL!>return@L<!> }
|
||||
fn()
|
||||
}
|
||||
|
||||
fun testHighOrderFunctionCallLabelInReturn() {
|
||||
L@ run {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> run {
|
||||
<!NOT_A_FUNCTION_LABEL!>return@L<!>
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -51,12 +51,12 @@ fun testLoopLabelInReturn(xs: List<Int>) {
|
||||
}
|
||||
|
||||
fun testValLabelInReturn() {
|
||||
L@ val fn = { <!NOT_A_FUNCTION_LABEL_WARNING!>return@L<!> }
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> val fn = { <!NOT_A_FUNCTION_LABEL_WARNING!>return@L<!> }
|
||||
fn()
|
||||
}
|
||||
|
||||
fun testHighOrderFunctionCallLabelInReturn() {
|
||||
L@ run {
|
||||
<!REDUNDANT_LABEL_WARNING!>L@<!> run {
|
||||
<!NOT_A_FUNCTION_LABEL_WARNING!>return@L<!>
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
public fun testAnnotatedLambdaLabel(): () -> kotlin.Unit
|
||||
public fun testAnonymousFunctionLabel(): () -> kotlin.Unit
|
||||
public fun testAnonymousObjectLabel(): kotlin.Any
|
||||
public fun testDoWhileLoopLabel(): kotlin.Unit
|
||||
public fun testForLoopLabel(/*0*/ xs: kotlin.collections.List<kotlin.Any>): kotlin.Unit
|
||||
public fun testHighOrderFunctionCallLabel(): kotlin.Unit
|
||||
public fun testLabelBoundToInvokeOperatorExpression(): kotlin.Int
|
||||
public fun testLabelBoundToLambda(): kotlin.Int
|
||||
public fun testLambdaLabel(): () -> kotlin.Int
|
||||
public fun testParenthesizedLambdaLabel(): () -> kotlin.Unit
|
||||
public fun testValLabel(): kotlin.Unit
|
||||
public fun testWhileLoopLabel(): kotlin.Unit
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.EXPRESSION}) @kotlin.annotation.Retention(value = AnnotationRetention.SOURCE) public final annotation class Ann : kotlin.Annotation {
|
||||
public constructor Ann()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user