diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt index 64378ed6137..9993a04de74 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt @@ -150,8 +150,10 @@ internal fun createSimplePSICallArgument( val preparedType = prepareArgumentTypeRegardingCaptureTypes(baseType) ?: baseType 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) { ExpressionKotlinCallArgumentImpl(valueArgument, context.dataFlowInfo, typeInfo.dataFlowInfo, receiverToCast) diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.kt b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.kt new file mode 100644 index 00000000000..cd84f8e6797 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.kt @@ -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 > Array<*>.filterIsInstanceTo(destination: C): C { + for (element in this) if (element is R) destination.add(element) + return destination +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.txt b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.txt new file mode 100644 index 00000000000..da04b3de95c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartCastAndArgumentApproximation.txt @@ -0,0 +1,3 @@ +package + +public inline fun > kotlin.Array<*>.filterIsInstanceTo(/*0*/ destination: C): C diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index e5e8cbcacbf..02d765a550c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -20056,6 +20056,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { 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") public void testSmartCastOnElvis() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/smartCastOnElvis.kt");