diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 5f9104010f2..267dad3c8ed 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -77,6 +77,7 @@ class ResolvedAtomCompleter( is ResolvedCallableReferenceAtom -> completeCallableReference(resolvedAtom) is ResolvedLambdaAtom -> completeLambda(resolvedAtom) is ResolvedCallAtom -> completeResolvedCall(resolvedAtom, emptyList()) + is ResolvedSubCallArgument -> completeSubCallArgument(resolvedAtom) is PartialCallResolutionResult -> completeResolvedCall(resolvedAtom.resultCallAtom, resolvedAtom.diagnostics) } } @@ -90,6 +91,17 @@ class ResolvedAtomCompleter( complete(resolvedAtom) } + fun completeSubCallArgument(resolvedSubCallArgument: ResolvedSubCallArgument) { + val contextWithoutExpectedType = topLevelCallContext.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE) + kotlinToResolvedCallTransformer.updateRecordedType( + resolvedSubCallArgument.atom.psiExpression ?: return, + parameter = null, + context = contextWithoutExpectedType, + reportErrorForTypeMismatch = true, + convertedArgumentType = null + ) + } + fun completeResolvedCall(resolvedCallAtom: ResolvedCallAtom, diagnostics: Collection): ResolvedCall<*>? { clearPartiallyResolvedCall(resolvedCallAtom) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt index 0152510cb05..243749feb43 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt @@ -179,7 +179,7 @@ private fun checkSubCallArgument( diagnosticsHolder: KotlinDiagnosticsHolder, receiverInfo: ReceiverInfo, ): ResolvedAtom { - val subCallResult = subCallArgument.callResult + val subCallResult = ResolvedSubCallArgument(subCallArgument) if (expectedType == null) return subCallResult diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt index d8317281573..fd9fdd12974 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt @@ -44,7 +44,7 @@ interface SimpleKotlinCallArgument : KotlinCallArgument, ReceiverKotlinCallArgum interface ExpressionKotlinCallArgument : SimpleKotlinCallArgument, ResolutionAtom -interface SubKotlinCallArgument : SimpleKotlinCallArgument { +interface SubKotlinCallArgument : SimpleKotlinCallArgument, ResolutionAtom { val callResult: PartialCallResolutionResult } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt index 05bb4b62793..1ed07c89d9b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt @@ -85,6 +85,12 @@ class ResolvedExpressionAtom(override val atom: ExpressionKotlinCallArgument) : } } +class ResolvedSubCallArgument(override val atom: SubKotlinCallArgument) : ResolvedAtom() { + init { + setAnalyzedResults(listOf(atom.callResult)) + } +} + interface PostponedResolvedAtomMarker { val inputTypes: Collection val outputType: KotlinTypeMarker? diff --git a/compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt b/compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt new file mode 100644 index 00000000000..89f75bbd616 --- /dev/null +++ b/compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt @@ -0,0 +1,20 @@ +class Inv + +fun Inv<*>.invToInv(): Inv<*>? = null + +fun myRun(block: () -> R): R { + return block() +} + +fun test(c: Inv<*>) { + myRun { + if (true) return@myRun // coerction to Unit + + c.invToInv()?.let {} + } +} + +fun box(): String { + test(Inv()) + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9fb0a04f9bc..6e70c2abaec 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12770,6 +12770,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b9559d553f6..b4dc2a6cb40 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12770,6 +12770,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 3882f26b590..927ce887bad 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -11640,6 +11640,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 6cad78fd412..8e115c53db6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11640,6 +11640,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 316e849ce43..ff12559868c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -9990,6 +9990,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 3b475930c39..92967c96df3 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -10055,6 +10055,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt"); } + @TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt") + public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception { + runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt"); + } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");