[NI] Fix smartcasts computation for dot-qualifier expressions
This commit is contained in:
+2
-1
@@ -180,7 +180,8 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
override fun createReceiverWithSmartCastInfo(resolvedAtom: ResolvedCallAtom): ReceiverValueWithSmartCastInfo? {
|
override fun createReceiverWithSmartCastInfo(resolvedAtom: ResolvedCallAtom): ReceiverValueWithSmartCastInfo? {
|
||||||
val returnType = resolvedAtom.candidateDescriptor.returnType ?: return null
|
val returnType = resolvedAtom.candidateDescriptor.returnType ?: return null
|
||||||
val psiKotlinCall = resolvedAtom.atom.psiKotlinCall
|
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(
|
return transformToReceiverWithSmartCastInfo(
|
||||||
resolvedAtom.candidateDescriptor,
|
resolvedAtom.candidateDescriptor,
|
||||||
|
|||||||
+9
@@ -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<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -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
|
// See also: KT-11998
|
||||||
data class My(val x: Boolean?)
|
data class My(val x: Boolean?)
|
||||||
|
|
||||||
@@ -7,7 +6,7 @@ fun doIt() {}
|
|||||||
fun foo(my: My) {
|
fun foo(my: My) {
|
||||||
if (my.x != null) {
|
if (my.x != null) {
|
||||||
// my.x should be smart-cast
|
// 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<!>) {
|
when (<!DEBUG_INFO_SMARTCAST!>my.x<!>) {
|
||||||
true -> doIt()
|
true -> doIt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21469,6 +21469,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("variables.kt")
|
||||||
public void testVariables() throws Exception {
|
public void testVariables() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");
|
||||||
|
|||||||
Generated
+6
@@ -21469,6 +21469,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("variables.kt")
|
||||||
public void testVariables() throws Exception {
|
public void testVariables() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/castchecks/variables.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user