[NI] Fix smartcasts computation for dot-qualifier expressions

This commit is contained in:
Mikhail Zarechenskiy
2018-04-16 17:43:07 +03:00
parent 55da251ffc
commit 3318549622
6 changed files with 35 additions and 3 deletions
@@ -180,7 +180,8 @@ class KotlinResolutionCallbacksImpl(
override fun createReceiverWithSmartCastInfo(resolvedAtom: ResolvedCallAtom): ReceiverValueWithSmartCastInfo? {
val returnType = resolvedAtom.candidateDescriptor.returnType ?: return null
val psiKotlinCall = resolvedAtom.atom.psiKotlinCall
val expression = psiKotlinCall.psiCall.callElement.safeAs<KtExpression>() ?: return null
val callElement = psiKotlinCall.psiCall.callElement.safeAs<KtExpression>() ?: return null
val expression = findCommonParent(callElement, resolvedAtom.atom.psiKotlinCall.explicitReceiver)
return transformToReceiverWithSmartCastInfo(
resolvedAtom.candidateDescriptor,
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
class Item(val link: String?)
fun test(item: Item) {
if (item.link != null) {
val href: String = <!DEBUG_INFO_SMARTCAST!>item.link<!>
}
}
@@ -0,0 +1,11 @@
package
public fun test(/*0*/ item: Item): kotlin.Unit
public final class Item {
public constructor Item(/*0*/ link: kotlin.String?)
public final val link: kotlin.String?
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,4 +1,3 @@
// !WITH_NEW_INFERENCE
// See also: KT-11998
data class My(val x: Boolean?)
@@ -7,7 +6,7 @@ fun doIt() {}
fun foo(my: My) {
if (my.x != null) {
// my.x should be smart-cast
if (<!DEBUG_INFO_SMARTCAST!>my.<!NI;TYPE_MISMATCH!>x<!><!>) doIt()
if (<!DEBUG_INFO_SMARTCAST!>my.x<!>) doIt()
when (<!DEBUG_INFO_SMARTCAST!>my.x<!>) {
true -> doIt()
}
@@ -21469,6 +21469,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("smartCastOfNullableExpressionWithExpectedType.kt")
public void testSmartCastOfNullableExpressionWithExpectedType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.kt");
doTest(fileName);
}
@TestMetadata("variables.kt")
public void testVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");
@@ -21469,6 +21469,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
doTest(fileName);
}
@TestMetadata("smartCastOfNullableExpressionWithExpectedType.kt")
public void testSmartCastOfNullableExpressionWithExpectedType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/smartCastOfNullableExpressionWithExpectedType.kt");
doTest(fileName);
}
@TestMetadata("variables.kt")
public void testVariables() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");