Support subject variable in specialized code generators for 'when'

This commit is contained in:
Dmitry Petrov
2018-06-09 17:00:25 +03:00
parent 3528405666
commit 34b76a3718
17 changed files with 427 additions and 20 deletions
@@ -0,0 +1,26 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// WITH_RUNTIME
// IGNORE_BACKEND: JS
fun dense(x: Int): Int {
return when (val xx = x) {
-4 -> 9
-1 -> 10
0 -> x + 11
1 -> 12
4 -> 13
5 -> 14
6 -> 15
7 -> 16
8 -> 17
9 -> x + 9
else -> 19
}
}
fun box(): String {
var result = (-5..10).map(::dense).joinToString()
if (result != "19, 9, 19, 19, 10, 11, 12, 19, 19, 13, 14, 15, 16, 17, 18, 19") return "dense:" + result
return "OK"
}