Introduce separate callee expression for when with subject variable

'Subject.Error' is redundant.
'Subject.None' can be an object.
'Subject#dataFlowValue' can be a lateinit property.

TODO: fix
- parsing local extension properties in 'when' subject
- parsing destructuring declarations in 'when' subject
- non-completed calls in nested 'when' with subject variable
- non-completed calls for subject variable in 'in' pattern
This commit is contained in:
Dmitry Petrov
2017-10-23 13:42:27 +03:00
parent a76bf57694
commit 091b935c2d
10 changed files with 90 additions and 77 deletions
@@ -2,10 +2,26 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun foo(): Any = 42
fun useInt(i: Int) {}
fun test(y: Any) {
val z = when (val <!NAME_SHADOWING!>y<!> = foo()) {
42 -> "Magic: $y"
else -> "Not magic: $y"
fun testShadowingParameter(y: Any) {
when (val <!NAME_SHADOWING!>y<!> = foo()) {
else -> {}
}
}
fun testShadowedInWhenBody(x: Any) {
when (val y = x) {
is String -> {
val <!NAME_SHADOWING!>y<!> = <!DEBUG_INFO_SMARTCAST!>y<!>.length
useInt(y)
}
}
}
fun testShadowinLocalVariable() {
val y = foo()
when (val <!NAME_SHADOWING!>y<!> = foo()) {
else -> {}
}
}
@@ -1,4 +1,7 @@
package
public fun foo(): kotlin.Any
public fun test(/*0*/ y: kotlin.Any): kotlin.Unit
public fun testShadowedInWhenBody(/*0*/ x: kotlin.Any): kotlin.Unit
public fun testShadowinLocalVariable(): kotlin.Unit
public fun testShadowingParameter(/*0*/ y: kotlin.Any): kotlin.Unit
public fun useInt(/*0*/ i: kotlin.Int): kotlin.Unit
@@ -0,0 +1,8 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun test(x: Any) {
when (val y = x) {
is String -> {}
}
}
@@ -0,0 +1,3 @@
package
public fun test(/*0*/ x: kotlin.Any): kotlin.Unit
@@ -2,8 +2,6 @@
// !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
@@ -15,26 +13,16 @@ fun testSimpleValInWhenSubject() {
fun testValWithoutInitializerWhenSubject() {
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val y: Any<!>) {
is String -> <!UNINITIALIZED_VARIABLE!>y<!>.<!UNRESOLVED_REFERENCE!>length<!>
is String -> <!UNINITIALIZED_VARIABLE, DEBUG_INFO_SMARTCAST!>y<!>.length
}
}
fun testVarInWhenSubject() {
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>var y = foo()<!>) {
is String -> y.<!UNRESOLVED_REFERENCE!>length<!>
is String -> <!DEBUG_INFO_SMARTCAST!>y<!>.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 }<!>) {
}
@@ -2,21 +2,7 @@ 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
}