Add quick fixes for SMARTCAST_IMPOSSIBLE in 'if' #KT-27184 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a0162adbf9
commit
cf3215b96e
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
if (x != null) <caret>x.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
x?.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
if (x != null) {
|
||||
<caret>x.length
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
x?.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
if (x != null) foo(<caret>x)
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
x?.let { foo(it) }
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
if (x is String) <caret>x.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
(x as? String)?.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
if (x is String) foo(x<caret>)
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'if' expression with safe access expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
(x as? String)?.let { foo(it) }
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = if (x != null) <caret>x.length else 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = x?.length ?: 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = if (x != null) {
|
||||
<caret>x.length
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = x?.length ?: 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = if (x != null) foo(<caret>x) else bar()
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
|
||||
fun bar() = 0
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = x?.let { foo(it) } ?: bar()
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
|
||||
fun bar() = 0
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
val i = if (x is String) <caret>x.length else 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
val i = (x as? String)?.length ?: 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
val i = if (x is String) foo(<caret>x) else bar()
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
|
||||
fun bar() = 0
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace 'if' expression with elvis expression" "true"
|
||||
// WITH_RUNTIME
|
||||
class Test {
|
||||
var x: Any? = null
|
||||
|
||||
fun test() {
|
||||
val i = (x as? String)?.let { foo(it) } ?: bar()
|
||||
}
|
||||
|
||||
fun foo(s: String) = 1
|
||||
|
||||
fun bar() = 0
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace 'if' expression with elvis expression" "false"
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Introduce local variable
|
||||
// DISABLE-ERRORS
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
val i = if (x != null) {
|
||||
bar()
|
||||
<caret>x.length
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace 'if' expression with safe access expression" "false"
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Introduce local variable
|
||||
// DISABLE-ERRORS
|
||||
class Test {
|
||||
var x: String? = ""
|
||||
|
||||
fun test() {
|
||||
if (x != null) {
|
||||
bar()
|
||||
<caret>x.length
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
Reference in New Issue
Block a user