diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index a959fb8826b..d87d2352b49 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -2485,6 +2485,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract public void testTypeDepthForTypeAlias() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/typeDepthForTypeAlias.kt"); } + + @TestMetadata("unitUpperBound.kt") + public void testUnitUpperBound() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/inlineClasses") diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.fir.txt new file mode 100644 index 00000000000..a9ad8499b28 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.fir.txt @@ -0,0 +1,15 @@ +FILE: unitUpperBound.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final fun foo(x: R|kotlin/collections/List|): R|kotlin/Unit| { + lvar w: R|kotlin/Int| = Int(1) + R|/x|.R|kotlin/collections/ifEmpty||, R|kotlin/Any|>( = ifEmpty@fun (): R|kotlin/Any| { + R|/w| = R|/w|.R|kotlin/Int.plus|(Int(2)) + } + ) + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt b/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt new file mode 100644 index 00000000000..d4205261214 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt @@ -0,0 +1,11 @@ +// WITH_STDLIB +// FULL_JDK + +class A { + fun foo(x: List) { + var w = 1 + x.ifEmpty { + w += 2 + } + } +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index a9087c22e2d..a3316a8ab8f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -2828,6 +2828,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testTypeDepthForTypeAlias() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/typeDepthForTypeAlias.kt"); } + + @Test + @TestMetadata("unitUpperBound.kt") + public void testUnitUpperBound() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index c29818f1dfc..7b107bab6c0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -2828,6 +2828,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testTypeDepthForTypeAlias() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/typeDepthForTypeAlias.kt"); } + + @Test + @TestMetadata("unitUpperBound.kt") + public void testUnitUpperBound() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/unitUpperBound.kt"); + } } @Nested diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt index 000cfad176e..e0846c05a03 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt @@ -197,10 +197,9 @@ class PostponedArgumentsAnalyzer( } if (!hasExpressionInReturnArguments && lambdaReturnType != null) { - /*LambdaArgumentConstraintPosition(lambda)*/ - c.getBuilder().addEqualityConstraint( - lambdaReturnType, + c.getBuilder().addSubtypeConstraint( components.session.builtinTypes.unitType.type, + lambdaReturnType, ConeLambdaArgumentConstraintPosition(lambda.atom) ) }