[NI] Use alternative to intersection type in public declarations
The new inference uses inferred intersection types normally, unlike the old inference.
However, intersection types in public declarations are approximated to supertype, which
potentially may give a less presice type, then it would be with the OI.
For non-related T1, T2 the NI approximates {T1 & T2} to Any in public declarations,
and if the OI was inferring T1 instead of the intersection type, it may lead to
less precise declaration type and related errors.
The solution is to remember an alternative for an intersection type when present.
Before approximation the alternative replaces the intersection type.
^KT-36249 Fixed
This commit is contained in:
@@ -557,4 +557,11 @@ class ConeTypeCheckerContext(
|
||||
else
|
||||
ConeTypeCheckerContext(errorTypesEqualToAnything, stubTypesEqualToAnything, session)
|
||||
|
||||
override fun createTypeWithAlternativeForIntersectionResult(
|
||||
firstCandidate: KotlinTypeMarker,
|
||||
secondCandidate: KotlinTypeMarker
|
||||
): KotlinTypeMarker {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Generated
+83
@@ -10226,6 +10226,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelIntersection.kt")
|
||||
public void testTopLevelIntersection() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/topLevelIntersection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
||||
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
||||
@@ -11022,6 +11027,84 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class PublicApproximation extends AbstractFirOldFrontendDiagnosticsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPublicApproximation() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/publicApproximation"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("approximatedIntersectionMorePreciseThanBound.kt")
|
||||
public void testApproximatedIntersectionMorePreciseThanBound() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/approximatedIntersectionMorePreciseThanBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("chainedLambdas.kt")
|
||||
public void testChainedLambdas() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/chainedLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("declarationTypes.kt")
|
||||
public void testDeclarationTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/declarationTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionAfterSmartCastInLambdaReturn.kt")
|
||||
public void testIntersectionAfterSmartCastInLambdaReturn() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/intersectionAfterSmartCastInLambdaReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionAlternative.kt")
|
||||
public void testIntersectionAlternative() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/intersectionAlternative.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionLocations.kt")
|
||||
public void testIntersectionLocations() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/intersectionLocations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaReturnArgumentCall.kt")
|
||||
public void testLambdaReturnArgumentCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/lambdaReturnArgumentCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaReturnTypeApproximation.kt")
|
||||
public void testLambdaReturnTypeApproximation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/lambdaReturnTypeApproximation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonTrivialVariance.kt")
|
||||
public void testNonTrivialVariance() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/nonTrivialVariance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterInBound.kt")
|
||||
public void testParameterInBound() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/parameterInBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("projections.kt")
|
||||
public void testProjections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/projections.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastInLambdaReturnAfterIntersection.kt")
|
||||
public void testSmartCastInLambdaReturnAfterIntersection() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/smartCastInLambdaReturnAfterIntersection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("twoIntersections.kt")
|
||||
public void testTwoIntersections() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/publicApproximation/twoIntersections.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveCalls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+5
@@ -1901,6 +1901,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt35847.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt36249.kt")
|
||||
public void testKt36249() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt36249.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4975.kt")
|
||||
public void testKt4975() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt");
|
||||
|
||||
Reference in New Issue
Block a user