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:
committed by
Ilya Kirillov
parent
0eaab6d8a2
commit
e1b542314a
@@ -377,7 +377,7 @@ private fun checkApplicabilityForArgumentType(
|
||||
|
||||
// Reaching here means argument types mismatch, and we want to record whether it's due to the nullability by checking a subtype
|
||||
// relation with nullable expected type.
|
||||
val isMismatchDueToNullability = AbstractTypeChecker.isSubtypeOf(
|
||||
val isMismatchDueToNullability = argumentType.canBeNull && !actualExpectedType.isNullable && AbstractTypeChecker.isSubtypeOf(
|
||||
context.session.typeContext,
|
||||
argumentType,
|
||||
actualExpectedType.withNullability(ConeNullability.NULLABLE, context.session.typeContext)
|
||||
|
||||
@@ -347,6 +347,8 @@ fun PsiElement.parameterIndex(): Int {
|
||||
}
|
||||
}
|
||||
|
||||
val KtValueArgument.argumentIndex: Int get() = (parent as KtValueArgumentList).arguments.indexOf(this)
|
||||
|
||||
fun KtModifierListOwner.isPrivate(): Boolean = hasModifier(KtTokens.PRIVATE_KEYWORD)
|
||||
|
||||
fun KtModifierListOwner.isProtected(): Boolean = hasModifier(KtTokens.PROTECTED_KEYWORD)
|
||||
|
||||
Reference in New Issue
Block a user