Move variable declaration into when: don't report when property has 'return' or 'throw'

#KT-31999 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-09-19 09:25:40 +09:00
committed by Mikhail Glukhikh
parent d9d04fc556
commit 877e583a96
6 changed files with 58 additions and 0 deletions
@@ -0,0 +1,8 @@
// PROBLEM: none
fun test(str: String?): String? {
val <caret>some = str ?: return null
return when (some) {
"some" -> some
else -> ""
}
}
@@ -0,0 +1,8 @@
// PROBLEM: none
fun test(str: String?): String? {
val <caret>some = if (str != null) str + str else return null
return when (some) {
"some" -> some
else -> ""
}
}
@@ -0,0 +1,8 @@
// PROBLEM: none
fun test(str: String?): String? {
val <caret>some = str ?: throw Exception()
return when (some) {
"some" -> some
else -> ""
}
}
@@ -0,0 +1,8 @@
// PROBLEM: none
fun test(str: String?): String? {
val <caret>some = if (str != null) str + str else throw Exception()
return when (some) {
"some" -> some
else -> ""
}
}