Add deprecation warning for false-negative TYPE_MISMATCH

See KT-49404 for details

In K1, within SubstitutingScope we approximate almost all the types
containing captured types are being approximated to either a lower or
an upper bound.

While mostly, it's being done correctly there are some problems with
approximations for flexible types

So, the parameter's type of A<in Any>::foo is approximated to Inv<in Any!>,
thus allowing to use Inv<*>, while it's obviously unsound.

NB: For the similar example, in B, there are regular TYPE_MISMATCH
because parameter for B<in Any>::foo is approximated to Nothing

Also, it's important to say that
- in K2 everything works because we don't use type approximation there
- approximation algorithm that works incorrectly is only being used in K1

^KT-54332 Fixed
This commit is contained in:
Denis.Zharkov
2022-10-06 13:08:37 +02:00
committed by Space Team
parent 4b455c0e51
commit 31ba1f1534
13 changed files with 384 additions and 1 deletions
@@ -33981,6 +33981,44 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/warningsForBreakingChanges")
@TestDataPath("$PROJECT_ROOT")
public class WarningsForBreakingChanges {
@Test
public void testAllFilesPresentInWarningsForBreakingChanges() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/warningsForBreakingChanges"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/warningsForBreakingChanges/capturedTypes")
@TestDataPath("$PROJECT_ROOT")
public class CapturedTypes {
@Test
public void testAllFilesPresentInCapturedTypes() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/warningsForBreakingChanges/capturedTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("incorrectCapturedApproximationForValueParameters.kt")
public void testIncorrectCapturedApproximationForValueParameters() throws Exception {
runTest("compiler/testData/diagnostics/tests/warningsForBreakingChanges/capturedTypes/incorrectCapturedApproximationForValueParameters.kt");
}
@Test
@TestMetadata("noWarningAfterSmartcast.kt")
public void testNoWarningAfterSmartcast() throws Exception {
runTest("compiler/testData/diagnostics/tests/warningsForBreakingChanges/capturedTypes/noWarningAfterSmartcast.kt");
}
@Test
@TestMetadata("noWarningOnSAMAdaption.kt")
public void testNoWarningOnSAMAdaption() throws Exception {
runTest("compiler/testData/diagnostics/tests/warningsForBreakingChanges/capturedTypes/noWarningOnSAMAdaption.kt");
}
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/when")
@TestDataPath("$PROJECT_ROOT")