[FIR] Fix capturing of flexible types during resolution

Previously, because we didn't handle flexible types properly in
prepareCapturedType, projections inside flexible types would only be
captured during subtyping with captureStatus=FOR_SUBTYPING
which would lead to the constraint type being wrongly approximated
(see ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint).

Fixing the capturing produced two kinds of false positive diagnostics:

1. In ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint we would get two instances of cone types
that are structurally equal and containing the same captured type.
However, because we only skipped subtyping if the types were
referentially equal, we would get a contradiction here.
The fix was to use structural equality instead, which should be okay
as the captured type instances are the same.

2. Reified type variables were inferred to captured types because
flexible arrays with captured upper bounds
(Array<Foo>..Array<Captured(out Foo)>?) were not properly approximated.

#KT-62609 Fixed
This commit is contained in:
Kirill Rakhman
2023-11-21 16:51:50 +01:00
committed by Space Team
parent ed4941d9f9
commit 560c1cacf3
16 changed files with 148 additions and 46 deletions
@@ -16424,6 +16424,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/kt619.kt");
}
@Test
@TestMetadata("kt62609.kt")
public void testKt62609() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt62609.kt");
}
@Test
@TestMetadata("lambdaArgumentWithLabel.kt")
public void testLambdaArgumentWithLabel() throws Exception {
@@ -16424,6 +16424,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/kt619.kt");
}
@Test
@TestMetadata("kt62609.kt")
public void testKt62609() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt62609.kt");
}
@Test
@TestMetadata("lambdaArgumentWithLabel.kt")
public void testLambdaArgumentWithLabel() throws Exception {