FIR IDE: quickfix for WrapWithSafeLetCall

There is some behavior change regarding the new WrapWithSafeLetCall quickfix

1. it now works correctly on binary expressions by wrapping it with `()`
2. it now looks for a nullable position upward and do the modification there,
   if possible. For example, consider the following code

   ```
   fun bar(s: String): String = s

   fun test(s: String?) {
     bar(bar(bar(<caret>s)))
   }
   ```

   After applying this fix, FE1.0 yields

   ```
   bar(bar(s?.let { bar(it) }))
   ```

   while the new implementation yields

   ```
   s?.let { bar(bar(bar(it))) }
   ```

   This behavior aligns with FE1.0 if `bar` accepts nullable values.
This commit is contained in:
Tianyu Geng
2021-04-28 23:20:53 +02:00
committed by Ilya Kirillov
parent 0eaab6d8a2
commit e1b542314a
62 changed files with 1190 additions and 26 deletions
@@ -0,0 +1,16 @@
// "Wrap with '?.let { ... }' call" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Convert to run
// ACTION: Convert to with
// ACTION: Replace with safe (?.) call
// ACTION: Surround with null check
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type B?
// WITH_RUNTIME
class A {
fun foo() {}
}
class B(val a: A)
fun test(b: B?) {
b<caret>.a.foo() // b.a is UNSAFE_CALL
}