Report error on illegal variable declaration in when subject
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class P(val x: Any, val y: Any)
|
||||
|
||||
fun foo(): Any = 42
|
||||
fun String.bar(): Any = 42
|
||||
|
||||
|
||||
fun testSimpleValInWhenSubject() {
|
||||
when (val y = foo()) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testValWithoutInitializerWhenSubject() {
|
||||
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val y: Any<!>) {
|
||||
is String -> <!UNINITIALIZED_VARIABLE!>y<!>.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testVarInWhenSubject() {
|
||||
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>var y = foo()<!>) {
|
||||
is String -> y.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testDestructuringInWhenSubject() {
|
||||
when (val (y1, y2) = P(1, 2)) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testExtensionValInWhenSubject() {
|
||||
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val <!LOCAL_EXTENSION_PROPERTY, DEBUG_INFO_MISSING_UNRESOLVED!>String<!>.<!VARIABLE_WITH_NO_TYPE_NO_INITIALIZER!>len<!><!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>get<!>(<!SYNTAX!><!>) = <!UNRESOLVED_REFERENCE!>bar<!>()<!SYNTAX!>)<!> <!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
}<!>
|
||||
}
|
||||
|
||||
fun testDelegatedValInWhenSubject() {
|
||||
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val y by <!UNRESOLVED_REFERENCE!>lazy<!> { 42 }<!>) {
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Any
|
||||
public fun testDelegatedValInWhenSubject(): kotlin.Unit
|
||||
public fun testDestructuringInWhenSubject(): kotlin.Unit
|
||||
public fun testExtensionValInWhenSubject(): kotlin.Unit
|
||||
public fun testSimpleValInWhenSubject(): kotlin.Unit
|
||||
public fun testValWithoutInitializerWhenSubject(): kotlin.Unit
|
||||
public fun testVarInWhenSubject(): kotlin.Unit
|
||||
public fun kotlin.String.bar(): kotlin.Any
|
||||
|
||||
public final data class P {
|
||||
public constructor P(/*0*/ x: kotlin.Any, /*1*/ y: kotlin.Any)
|
||||
public final val x: kotlin.Any
|
||||
public final val y: kotlin.Any
|
||||
public final operator /*synthesized*/ fun component1(): kotlin.Any
|
||||
public final operator /*synthesized*/ fun component2(): kotlin.Any
|
||||
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Any = ..., /*1*/ y: kotlin.Any = ...): P
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user