K2: Avoid inappropriate approximation of captured type to Nothing?

There's a heuristic for approximation of a captured type that once
it has non-trivial lower bound (other than Nothing), it's worth
approximating it to sub-type even while the containing
top-level type is being approximated to super-type.

And that sounds reasonable in case the lower bound is indeed non-trivial,
but that's not the case because nullability here comes from
the nullability of captured type position.

So, the fix is basically not to treat such approximations as non-trivial.
And while that seems to be a bit of a change in the language semantics,
it still looks reasonable (see other changes in test data and KT-58087)

^KT-57958 Fixed
^KT-58087 Fixed
This commit is contained in:
Denis.Zharkov
2023-04-18 19:07:30 +02:00
committed by Space Team
parent 0a631ed8fc
commit 6651e6ed8c
10 changed files with 189 additions and 16 deletions
@@ -15417,6 +15417,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/approximateContravariantCapturedTypes.kt");
}
@Test
@TestMetadata("approximationLeavesNonTrivialLowerBound.kt")
public void testApproximationLeavesNonTrivialLowerBound() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt");
}
@Test
@TestMetadata("avoidCreatingUselessCapturedTypes.kt")
public void testAvoidCreatingUselessCapturedTypes() throws Exception {
@@ -15441,6 +15447,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.kt");
}
@Test
@TestMetadata("captureFromNullableTypeInScope.kt")
public void testCaptureFromNullableTypeInScope() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScope.kt");
}
@Test
@TestMetadata("captureFromNullableTypeInScopeAny.kt")
public void testCaptureFromNullableTypeInScopeAny() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt");
}
@Test
@TestMetadata("captureFromNullableTypeVariable.kt")
public void testCaptureFromNullableTypeVariable() throws Exception {
@@ -15417,6 +15417,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/approximateContravariantCapturedTypes.kt");
}
@Test
@TestMetadata("approximationLeavesNonTrivialLowerBound.kt")
public void testApproximationLeavesNonTrivialLowerBound() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt");
}
@Test
@TestMetadata("avoidCreatingUselessCapturedTypes.kt")
public void testAvoidCreatingUselessCapturedTypes() throws Exception {
@@ -15441,6 +15447,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureForPlatformTypes.kt");
}
@Test
@TestMetadata("captureFromNullableTypeInScope.kt")
public void testCaptureFromNullableTypeInScope() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScope.kt");
}
@Test
@TestMetadata("captureFromNullableTypeInScopeAny.kt")
public void testCaptureFromNullableTypeInScopeAny() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt");
}
@Test
@TestMetadata("captureFromNullableTypeVariable.kt")
public void testCaptureFromNullableTypeVariable() throws Exception {