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:
Dmitry Petrov
2018-06-08 11:25:17 +03:00
parent 758548603e
commit ae929d0f08
7 changed files with 88 additions and 20 deletions
@@ -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)
}
}
}