Handle nested when with subject properly
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').
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
// !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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user