Fix replacedBaseClause for selector which has implicit receiver
#KT-19666 Fixed
This commit is contained in:
+9
-2
@@ -165,13 +165,20 @@ data class IfThenToSelectData(
|
|||||||
it.leftHandSide,
|
it.leftHandSide,
|
||||||
it.typeReference!!)
|
it.typeReference!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (baseClauseEvaluatesToReceiver()) {
|
return if (baseClauseEvaluatesToReceiver()) {
|
||||||
if (condition is KtIsExpression) newReceiver!! else baseClause
|
if (condition is KtIsExpression) newReceiver!! else baseClause
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
when {
|
when {
|
||||||
condition is KtIsExpression -> (baseClause as KtDotQualifiedExpression).replaceFirstReceiver(
|
condition is KtIsExpression -> {
|
||||||
factory, newReceiver!!, safeAccess = true)
|
when {
|
||||||
|
baseClause is KtDotQualifiedExpression -> baseClause.replaceFirstReceiver(
|
||||||
|
factory, newReceiver!!, safeAccess = true)
|
||||||
|
hasImplicitReceiver() -> factory.createExpressionByPattern("$0?.$1", newReceiver!!, baseClause).insertSafeCalls(factory)
|
||||||
|
else -> error("Illegal state")
|
||||||
|
}
|
||||||
|
}
|
||||||
hasImplicitReceiver() -> factory.createExpressionByPattern("this?.$0", baseClause).insertSafeCalls(factory)
|
hasImplicitReceiver() -> factory.createExpressionByPattern("this?.$0", baseClause).insertSafeCalls(factory)
|
||||||
else -> baseClause.insertSafeCalls(factory)
|
else -> baseClause.insertSafeCalls(factory)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
interface Taggable {
|
||||||
|
val tag: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Any.log() {
|
||||||
|
val tag = <caret>if (this is Taggable) {
|
||||||
|
tag
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this::class.java.simpleName
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
interface Taggable {
|
||||||
|
val tag: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Any.log() {
|
||||||
|
val tag = (this as? Taggable)?.tag ?: this::class.java.simpleName
|
||||||
|
}
|
||||||
@@ -1423,6 +1423,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt19666.kt")
|
||||||
|
public void testKt19666() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/kt19666.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lhsEqualsNull.kt")
|
@TestMetadata("lhsEqualsNull.kt")
|
||||||
public void testLhsEqualsNull() throws Exception {
|
public void testLhsEqualsNull() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user