Wrap with let: apply to unsafe qualified expression

#KT-18125 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-07-08 09:50:03 +09:00
committed by Vladimir Dolzhenko
parent 18fbf5729d
commit 6db0785615
7 changed files with 83 additions and 12 deletions
+7
View File
@@ -0,0 +1,7 @@
// "Wrap with '?.let { ... }' call" "true"
// WITH_RUNTIME
fun foo(s: String) {}
fun bar(s: String?) {
foo(s<caret>.substring(1))
}
@@ -0,0 +1,7 @@
// "Wrap with '?.let { ... }' call" "true"
// WITH_RUNTIME
fun foo(s: String) {}
fun bar(s: String?) {
s?.let { foo(it.substring(1)) }
}
+13
View File
@@ -0,0 +1,13 @@
// "Wrap with '?.let { ... }' call" "true"
// WITH_RUNTIME
class A(val b: B)
class B {
fun c(s: String) {}
}
class X(val y: Y)
class Y(val z: String)
fun test(a: A, x: X?) {
a.b.c(x?.y<caret>.z)
}
@@ -0,0 +1,13 @@
// "Wrap with '?.let { ... }' call" "true"
// WITH_RUNTIME
class A(val b: B)
class B {
fun c(s: String) {}
}
class X(val y: Y)
class Y(val z: String)
fun test(a: A, x: X?) {
x?.y?.let { a.b.c(it.z) }
}
@@ -0,0 +1,12 @@
// "Wrap with '?.let { ... }' call" "false"
// ACTION: Add 's =' to argument
// ACTION: Add non-null asserted (!!) call
// ACTION: Replace with safe (?.) call
// ACTION: Surround with null check
// DISABLE-ERRORS
// WITH_RUNTIME
fun foo(s: String?) {}
fun bar(s: String?) {
foo(s<caret>.substring(1))
}