[NI] Fix smart cast for expression with captured input type.
This commit is contained in:
@@ -150,8 +150,10 @@ internal fun createSimplePSICallArgument(
|
|||||||
val preparedType = prepareArgumentTypeRegardingCaptureTypes(baseType) ?: baseType
|
val preparedType = prepareArgumentTypeRegardingCaptureTypes(baseType) ?: baseType
|
||||||
|
|
||||||
val receiverToCast = context.transformToReceiverWithSmartCastInfo(
|
val receiverToCast = context.transformToReceiverWithSmartCastInfo(
|
||||||
ExpressionReceiver.create(ktExpression, preparedType, context.trace.bindingContext)
|
ExpressionReceiver.create(ktExpression, baseType, context.trace.bindingContext)
|
||||||
)
|
).let {
|
||||||
|
ReceiverValueWithSmartCastInfo(it.receiverValue.replaceType(preparedType), it.possibleTypes, it.isStable)
|
||||||
|
}
|
||||||
|
|
||||||
return if (onlyResolvedCall == null) {
|
return if (onlyResolvedCall == null) {
|
||||||
ExpressionKotlinCallArgumentImpl(valueArgument, context.dataFlowInfo, typeInfo.dataFlowInfo, receiverToCast)
|
ExpressionKotlinCallArgumentImpl(valueArgument, context.dataFlowInfo, typeInfo.dataFlowInfo, receiverToCast)
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Here element has type Captured(*) because of resolution for `iterator()` on this.
|
||||||
|
and where we resolve `destination.add(element)` we approximate element to `Any` with smart cast to `R`.
|
||||||
|
*/
|
||||||
|
inline fun <reified R, C : MutableCollection<in R>> Array<*>.filterIsInstanceTo(destination: C): C {
|
||||||
|
for (element in this) if (element is R) destination.add(<!DEBUG_INFO_SMARTCAST!>element<!>)
|
||||||
|
return destination
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public inline fun </*0*/ reified R, /*1*/ C : kotlin.collections.MutableCollection<in R>> kotlin.Array<*>.filterIsInstanceTo(/*0*/ destination: C): C
|
||||||
@@ -20056,6 +20056,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("smartCastAndArgumentApproximation.kt")
|
||||||
|
public void testSmartCastAndArgumentApproximation() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("smartCastOnElvis.kt")
|
@TestMetadata("smartCastOnElvis.kt")
|
||||||
public void testSmartCastOnElvis() throws Exception {
|
public void testSmartCastOnElvis() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user