[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:
@@ -10233,6 +10233,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
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");
|
||||
@@ -11029,6 +11034,84 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class PublicApproximation extends AbstractDiagnosticsTestWithFirValidation {
|
||||
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("^(.*)\\.kts?$"), 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
@@ -2881,6 +2881,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
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");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2881,6 +2881,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
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");
|
||||
|
||||
Generated
+83
@@ -10228,6 +10228,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
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");
|
||||
@@ -11024,6 +11029,84 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class PublicApproximation extends AbstractDiagnosticsUsingJavacTest {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user