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.typeReference!!)
|
||||
}
|
||||
|
||||
return if (baseClauseEvaluatesToReceiver()) {
|
||||
if (condition is KtIsExpression) newReceiver!! else baseClause
|
||||
}
|
||||
else {
|
||||
when {
|
||||
condition is KtIsExpression -> (baseClause as KtDotQualifiedExpression).replaceFirstReceiver(
|
||||
factory, newReceiver!!, safeAccess = true)
|
||||
condition is KtIsExpression -> {
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
@TestMetadata("kt19666.kt")
|
||||
public void testKt19666() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/kt19666.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lhsEqualsNull.kt")
|
||||
public void testLhsEqualsNull() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt");
|
||||
|
||||
Reference in New Issue
Block a user