[FE 1.0] Report errors due to inferred empty intersection on those candidates which were already previously discriminated by CompatibilityOfTypeVariableAsIntersectionTypePart

This commit is contained in:
Victor Petukhov
2022-04-22 12:00:58 +03:00
committed by teamcity
parent 38913b68b2
commit 12a39d0330
9 changed files with 316 additions and 87 deletions
@@ -13492,12 +13492,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/commonSuperTypeOfTypesWithErrorSupertypes.kt");
}
@Test
@TestMetadata("compatibilityResolveWhenVariableHasComplexIntersectionType.kt")
public void testCompatibilityResolveWhenVariableHasComplexIntersectionType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/compatibilityResolveWhenVariableHasComplexIntersectionType.kt");
}
@Test
@TestMetadata("completeInferenceIfManyFailed.kt")
public void testCompleteInferenceIfManyFailed() throws Exception {
@@ -13834,36 +13828,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
}
@Test
@TestMetadata("kt45461.kt")
public void testKt45461() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
}
@Test
@TestMetadata("kt45461_2.kt")
public void testKt45461_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt");
}
@Test
@TestMetadata("kt45461_3.kt")
public void testKt45461_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_3.kt");
}
@Test
@TestMetadata("kt45461_4.kt")
public void testKt45461_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_4.kt");
}
@Test
@TestMetadata("kt45461_5.kt")
public void testKt45461_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt");
}
@Test
@TestMetadata("kt46515.kt")
public void testKt46515() throws Exception {
@@ -13876,36 +13840,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
}
@Test
@TestMetadata("kt48765.kt")
public void testKt48765() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48765.kt");
}
@Test
@TestMetadata("kt48935.kt")
public void testKt48935() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt");
}
@Test
@TestMetadata("kt49658.kt")
public void testKt49658() throws Exception {
@@ -13918,12 +13852,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
}
@Test
@TestMetadata("kt49661.kt")
public void testKt49661() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt49661.kt");
}
@Test
@TestMetadata("kt6175.kt")
public void testKt6175() throws Exception {
@@ -14901,12 +14829,6 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/postponedCompletionWithExactAnnotation_ni.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.kt");
}
@Test
@TestMetadata("selectFromTwoIncompatibleTypes.kt")
public void testSelectFromTwoIncompatibleTypes() throws Exception {
@@ -15280,6 +15202,304 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes")
@TestDataPath("$PROJECT_ROOT")
public class EmptyIntersectionTypes {
@Test
public void testAllFilesPresentInEmptyIntersectionTypes() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("compatibilityResolveWhenVariableHasComplexIntersectionType.kt")
public void testCompatibilityResolveWhenVariableHasComplexIntersectionType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/compatibilityResolveWhenVariableHasComplexIntersectionType.kt");
}
@Test
@TestMetadata("kt45461.kt")
public void testKt45461() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt");
}
@Test
@TestMetadata("kt45461_10.kt")
public void testKt45461_10() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_10.kt");
}
@Test
@TestMetadata("kt45461_11.kt")
public void testKt45461_11() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_11.kt");
}
@Test
@TestMetadata("kt45461_12.kt")
public void testKt45461_12() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_12.kt");
}
@Test
@TestMetadata("kt45461_13.kt")
public void testKt45461_13() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_13.kt");
}
@Test
@TestMetadata("kt45461_14.kt")
public void testKt45461_14() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_14.kt");
}
@Test
@TestMetadata("kt45461_15.kt")
public void testKt45461_15() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_15.kt");
}
@Test
@TestMetadata("kt45461_16.kt")
public void testKt45461_16() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_16.kt");
}
@Test
@TestMetadata("kt45461_17.kt")
public void testKt45461_17() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_17.kt");
}
@Test
@TestMetadata("kt45461_18.kt")
public void testKt45461_18() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_18.kt");
}
@Test
@TestMetadata("kt45461_19.kt")
public void testKt45461_19() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_19.kt");
}
@Test
@TestMetadata("kt45461_2.kt")
public void testKt45461_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_2.kt");
}
@Test
@TestMetadata("kt45461_20.kt")
public void testKt45461_20() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_20.kt");
}
@Test
@TestMetadata("kt45461_21.kt")
public void testKt45461_21() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_21.kt");
}
@Test
@TestMetadata("kt45461_22.kt")
public void testKt45461_22() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_22.kt");
}
@Test
@TestMetadata("kt45461_23.kt")
public void testKt45461_23() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_23.kt");
}
@Test
@TestMetadata("kt45461_24.kt")
public void testKt45461_24() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_24.kt");
}
@Test
@TestMetadata("kt45461_25.kt")
public void testKt45461_25() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_25.kt");
}
@Test
@TestMetadata("kt45461_26.kt")
public void testKt45461_26() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_26.kt");
}
@Test
@TestMetadata("kt45461_27.kt")
public void testKt45461_27() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_27.kt");
}
@Test
@TestMetadata("kt45461_28.kt")
public void testKt45461_28() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_28.kt");
}
@Test
@TestMetadata("kt45461_29.kt")
public void testKt45461_29() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_29.kt");
}
@Test
@TestMetadata("kt45461_3.kt")
public void testKt45461_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_3.kt");
}
@Test
@TestMetadata("kt45461_30.kt")
public void testKt45461_30() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_30.kt");
}
@Test
@TestMetadata("kt45461_31.kt")
public void testKt45461_31() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_31.kt");
}
@Test
@TestMetadata("kt45461_32.kt")
public void testKt45461_32() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_32.kt");
}
@Test
@TestMetadata("kt45461_33.kt")
public void testKt45461_33() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_33.kt");
}
@Test
@TestMetadata("kt45461_34.kt")
public void testKt45461_34() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_34.kt");
}
@Test
@TestMetadata("kt45461_35.kt")
public void testKt45461_35() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_35.kt");
}
@Test
@TestMetadata("kt45461_35_Enabled.kt")
public void testKt45461_35_Enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_35_Enabled.kt");
}
@Test
@TestMetadata("kt45461_4.kt")
public void testKt45461_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_4.kt");
}
@Test
@TestMetadata("kt45461_5.kt")
public void testKt45461_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_5.kt");
}
@Test
@TestMetadata("kt45461_6.kt")
public void testKt45461_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_6.kt");
}
@Test
@TestMetadata("kt45461_7.kt")
public void testKt45461_7() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_7.kt");
}
@Test
@TestMetadata("kt45461_8.kt")
public void testKt45461_8() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_8.kt");
}
@Test
@TestMetadata("kt45461_9.kt")
public void testKt45461_9() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461_9.kt");
}
@Test
@TestMetadata("kt48765.kt")
public void testKt48765() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48765.kt");
}
@Test
@TestMetadata("kt48935.kt")
public void testKt48935() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_4.kt");
}
@Test
@TestMetadata("kt48935_5.kt")
public void testKt48935_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_5.kt");
}
@Test
@TestMetadata("kt48935_6.kt")
public void testKt48935_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt48935_6.kt");
}
@Test
@TestMetadata("kt49661.kt")
public void testKt49661() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt49661.kt");
}
@Test
@TestMetadata("kt51016.kt")
public void testKt51016() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt51016.kt");
}
@Test
@TestMetadata("nullableEmptyIntersection.kt")
public void testNullableEmptyIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("selectFromCovariantAndContravariantTypes.kt")
public void testSelectFromCovariantAndContravariantTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/selectFromCovariantAndContravariantTypes.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/inference/nestedCalls")
@TestDataPath("$PROJECT_ROOT")
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -880,6 +881,13 @@ internal object CheckContextReceiversResolutionPart : ResolutionPart() {
}
internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
/*
* Check if the candidate was already discriminated by `CompatibilityOfTypeVariableAsIntersectionTypePart` resolution part
* If it's true we shouldn't mark the candidate with warning, but should mark with error, to repeat the existing proper behaviour
*/
private fun ResolutionCandidate.wasPreviouslyDiscriminated(upperTypes: List<KotlinTypeMarker>) =
callComponents.statelessCallbacks.isOldIntersectionIsEmpty(upperTypes.cast())
override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) {
for (variableWithConstraints in getSystem().getBuilder().currentStorage().notFixedTypeVariables.values) {
val upperTypes = variableWithConstraints.constraints.extractUpperTypesToCheckIntersectionEmptiness()
@@ -888,8 +896,9 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
val isInferredEmptyIntersectionForbidden =
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
val errorFactory =
if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning
val errorFactory = if (isInferredEmptyIntersectionForbidden || wasPreviouslyDiscriminated(upperTypes))
::InferredEmptyIntersectionError
else ::InferredEmptyIntersectionWarning
addError(errorFactory(upperTypes, variableWithConstraints.typeVariable))
}
}
@@ -11,5 +11,5 @@ interface B
fun <K : Inv<A>> main() {
val foo = Foo<K>()
Bar<Inv<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Inv<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -11,5 +11,5 @@ interface B<K> : A<Int>
fun <K : Out<A<String>>> main() {
val foo = Foo<K>()
Bar<Out<B<String>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Out<B<String>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -11,5 +11,5 @@ interface B : A<Int>
fun <K : Out<A<String>>> main() {
val foo = Foo<K>()
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -12,5 +12,5 @@ interface C : A<String>
fun <K : Out<C>> main() {
val foo = Foo<K>()
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -12,5 +12,5 @@ class C : A<String>
fun <K : <!FINAL_UPPER_BOUND!>Out<C><!>> main() {
val foo = Foo<K>()
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -11,5 +11,5 @@ class B : A<Int>
fun <K : Out<A<String>>> main() {
val foo = Foo<K>()
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
Bar<Out<B>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -53,5 +53,5 @@ fun main() {
select(id(::foo5), id { x: A -> }, id { x: B -> }, id { <!DEBUG_INFO_EXPRESSION_TYPE("C")!>it<!> })
val x2: (Int) -> Unit = selectNumber(id(::<!CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY!>foo6<!>), id { x -> <!DEBUG_INFO_EXPRESSION_TYPE("{Comparable<*> & Number}")!>x<!> }, id { <!DEBUG_INFO_EXPRESSION_TYPE("{Comparable<*> & Number}")!>it<!> })
val x2: (Int) -> Unit = selectNumber(id(::foo6), id { x -> <!DEBUG_INFO_EXPRESSION_TYPE("{Comparable<*> & Number}")!>x<!> }, id { <!DEBUG_INFO_EXPRESSION_TYPE("{Comparable<*> & Number}")!>it<!> })
}