Elvis -> if intention: don't produce boilerplate code for return/break/continue/throw in RHS

#KT-14369 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-05-15 00:58:19 +09:00
committed by Mikhail Glukhikh
parent 160de2dbe2
commit 2c424afefa
12 changed files with 87 additions and 0 deletions
@@ -0,0 +1,5 @@
fun foo(s: String?) {
while (true) {
val t = s?.hashCode() ?:<caret> break
}
}
@@ -0,0 +1,6 @@
fun foo(s: String?) {
while (true) {
val t = s?.hashCode()
if (t == null) break
}
}
@@ -0,0 +1,5 @@
fun foo(s: String?) {
while (true) {
val t = s?.hashCode() ?:<caret> continue
}
}
@@ -0,0 +1,6 @@
fun foo(s: String?) {
while (true) {
val t = s?.hashCode()
if (t == null) continue
}
}
@@ -0,0 +1,3 @@
fun foo(s: String?) {
val t = s?.hashCode() ?:<caret> return
}
@@ -0,0 +1,4 @@
fun foo(s: String?) {
val t = s?.hashCode()
if (t == null) return
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
fun foo(s: String?) {
val t = s?.hashCode() ?:<caret> throw Exception()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo(s: String?) {
val t = s?.hashCode()
if (t == null) throw Exception()
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = (arg as? My)?.x <caret>?: return
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = if (arg is My) arg.x else return
}