ae929d0f08
Hack: callee expression for when with subject variable is the subject variable declaration. This solves the problem that all sub-calls in the expression are implicitly considered to have a single common lexical scope (and 'when (val x = ...)' introduces a new lexical scope, which contains 'x').
41 lines
695 B
Kotlin
Vendored
41 lines
695 B
Kotlin
Vendored
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
|
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VALUE
|
|
|
|
fun foo() {}
|
|
fun <T> bar(x: T, y: T) {}
|
|
|
|
fun test1() {
|
|
when (1) {
|
|
1 ->
|
|
when (val y = 2) {
|
|
2 -> foo()
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test2() {
|
|
when (val x = 1) {
|
|
1 ->
|
|
when (val y = 2) {
|
|
2 -> foo()
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test3() {
|
|
when (val x = 1) {
|
|
1 ->
|
|
when (val <!NAME_SHADOWING!>x<!> = 2) {
|
|
2 -> foo()
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test4() {
|
|
when (val x = 1) {
|
|
1 ->
|
|
when (val y = 2) {
|
|
2 -> bar(x, y)
|
|
}
|
|
}
|
|
} |