if-then to safe access: fix for qualified 'this' condition #KT-26662 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b5f73ebd0f
commit
3f2c73b4a9
+1
-1
@@ -228,7 +228,7 @@ data class IfThenToSelectData(
|
|||||||
else -> error("Illegal state")
|
else -> error("Illegal state")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasImplicitReceiverReplaceableBySafeCall() -> factory.createExpressionByPattern("this?.$0", baseClause).insertSafeCalls(factory)
|
hasImplicitReceiverReplaceableBySafeCall() -> factory.createExpressionByPattern("$0?.$1", receiverExpression, baseClause).insertSafeCalls(factory)
|
||||||
baseClause is KtCallExpression -> baseClause.replaceCallWithLet(receiverExpression, factory)
|
baseClause is KtCallExpression -> baseClause.replaceCallWithLet(receiverExpression, factory)
|
||||||
else -> baseClause.insertSafeCalls(factory)
|
else -> baseClause.insertSafeCalls(factory)
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
class Foo {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Foo?.test() {
|
||||||
|
<caret>if (this@test != null) {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Foo?.test() {
|
||||||
|
this@test?.foo()
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
class Foo
|
||||||
|
|
||||||
|
class Bar {
|
||||||
|
fun Foo?.test() {
|
||||||
|
<caret>if (this@Bar != null) {
|
||||||
|
bar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun bar() {}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
class Foo
|
||||||
|
|
||||||
|
class Bar {
|
||||||
|
fun Foo?.test() {
|
||||||
|
this@Bar?.bar()
|
||||||
|
}
|
||||||
|
fun bar() {}
|
||||||
|
}
|
||||||
+10
@@ -166,6 +166,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver.kt");
|
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("implicitReceiver2.kt")
|
||||||
|
public void testImplicitReceiver2() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("implicitReceiver3.kt")
|
||||||
|
public void testImplicitReceiver3() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("implicitReceiverInApply.kt")
|
@TestMetadata("implicitReceiverInApply.kt")
|
||||||
public void testImplicitReceiverInApply() throws Exception {
|
public void testImplicitReceiverInApply() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiverInApply.kt");
|
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiverInApply.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user