Elvis -> if-then: handle case with safe cast separately #KT-17816 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-12-28 16:23:46 +03:00
parent ec60c92fe9
commit 5475f99cec
13 changed files with 133 additions and 6 deletions
@@ -0,0 +1,4 @@
class My(val x: Int?)
fun foo(arg: Any) {
val y = (arg as? My)?.x <caret>?: 42
}
@@ -0,0 +1,4 @@
class My(val x: Int?)
fun foo(arg: Any) {
val y = if ((arg as? My)?.x != null) (arg as? My)?.x else 42
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = (arg as? My)?.x?.hashCode() <caret>?: 42
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = if (arg is My) arg.x.hashCode() else 42
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = (arg as? My)?.x <caret>?: 42
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = if (arg is My) arg.x else 42
}
@@ -0,0 +1,5 @@
class My(var z: Any, val x: Int) {
fun foo() {
val y = (z as? My)?.x <caret>?: 42
}
}
@@ -0,0 +1,6 @@
class My(var z: Any, val x: Int) {
fun foo() {
val z1 = z
val y = if (z1 is My) z1 else 42
}
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = arg as? My <caret>?: My(42)
}
@@ -0,0 +1,4 @@
class My(val x: Int)
fun foo(arg: Any) {
val y = if (arg is My) arg else My(42)
}