Fix nullability quick-fixes with implicit receiver #KT-17726 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9d2ae54d2c
commit
46aaee5d05
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
|
||||
fun String?.foo() {
|
||||
<caret>length
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
|
||||
fun String?.foo() {
|
||||
this!!.length
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() {
|
||||
<caret>toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() {
|
||||
this!!.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
|
||||
fun foo(a: String?) {
|
||||
a<caret>.length
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
|
||||
fun foo(a: String?) {
|
||||
a!!.length
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(a: String?) {
|
||||
a<caret>.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add non-null asserted (!!) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(a: String?) {
|
||||
a!!.toLowerCase()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with safe (?.) call" "false"
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Convert to block body
|
||||
// ACTION: Replace overloaded operator with function call
|
||||
// ACTION: Replace with safe (this?.) call
|
||||
// ACTION: Wrap with '?.let { ... }' call
|
||||
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
|
||||
|
||||
fun String?.foo(exec: (String.() -> Unit)) = exec<caret>()
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(array: Array<String>?) {
|
||||
array<caret>[0]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(array: Array<String>?) {
|
||||
array?.get(0)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(array: Array<String>?) {
|
||||
array<caret>[0] = ""
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(array: Array<String>?) {
|
||||
array?.set(0, "")
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(bar: Int?) {
|
||||
bar +<caret> 1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(bar: Int?) {
|
||||
bar?.plus(1)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun bar() {
|
||||
val fff: (() -> Unit)? = ::foo
|
||||
<caret>fff()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun bar() {
|
||||
val fff: (() -> Unit)? = ::foo
|
||||
fff?.invoke()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(list: List<String>?) {
|
||||
list<caret>[0]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(list: List<String>?) {
|
||||
list?.get(0)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with dot call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String) {
|
||||
a<caret>?.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with dot call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String) {
|
||||
a.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with dot call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String) {
|
||||
a<caret>?.length
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with dot call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String) {
|
||||
a.length
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
this<caret>.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
this?.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
<caret>length
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
this?.length
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
<caret>toLowerCase()
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.apply {
|
||||
this?.toLowerCase()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() {
|
||||
<caret>toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (this?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun String?.foo() {
|
||||
this?.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a<caret>.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a?.toLowerCase()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.let {
|
||||
it<caret>.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.let {
|
||||
it?.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.let { b ->
|
||||
b<caret>.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a.let { b ->
|
||||
b?.length
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with safe (?.) call" "false"
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Convert to expression body
|
||||
// ACTION: Replace with safe (this?.) call
|
||||
// ACTION: Wrap with '?.let { ... }' call
|
||||
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type A?
|
||||
|
||||
class A {
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
fun A?.bar() {
|
||||
<caret>foo()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a<caret>.length
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with safe (?.) call" "true"
|
||||
// WITH_RUNTIME
|
||||
fun foo(a: String?) {
|
||||
a?.length
|
||||
}
|
||||
Reference in New Issue
Block a user