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 385022caaaa..6ba0cf30eac 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 @@ -133,7 +133,13 @@ class ResolvedAtomCompleter( resultSubstitutor.safeSubstitute(lambda.returnType) } - updateTraceForLambda(lambda, topLevelTrace, returnType) + val approximatedReturnType = + TypeApproximator().approximateDeclarationType( + returnType, + local = true, + languageVersionSettings = topLevelCallContext.languageVersionSettings + ) + updateTraceForLambda(lambda, topLevelTrace, approximatedReturnType) for (lambdaResult in lambda.resultArguments) { val resultValueArgument = lambdaResult as? PSIKotlinCallArgument ?: continue diff --git a/compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt b/compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt new file mode 100644 index 00000000000..d52996b9983 --- /dev/null +++ b/compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +class Foo { + fun test(candidates: Collection): List { + return candidates.sortedBy { 1 } + } +} + +fun box(): String { + val foo = Foo() + + val list = listOf("OK") + val sorted = foo.test(list) + + return list.first() +} \ 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 ec24c7eea9a..d20f74cbe70 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11870,6 +11870,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") + public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { + runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); + } + @TestMetadata("kt10822.kt") public void testKt10822() throws Exception { runTest("compiler/testData/codegen/box/inference/kt10822.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index d5518a9af85..a27e19e2174 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11870,6 +11870,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") + public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { + runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); + } + @TestMetadata("kt10822.kt") public void testKt10822() throws Exception { runTest("compiler/testData/codegen/box/inference/kt10822.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 3c2f648128b..4aed2a0238b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11875,6 +11875,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("integerLiteralTypeInLamdaReturnType.kt") + public void testIntegerLiteralTypeInLamdaReturnType() throws Exception { + runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt"); + } + @TestMetadata("kt10822.kt") public void testKt10822() throws Exception { runTest("compiler/testData/codegen/box/inference/kt10822.kt");