Elvis -> if-then: handle case with safe cast separately #KT-17816 Fixed
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user