[FE] Don't check intersection emptiness if there were lower constraints

This commit is contained in:
Victor Petukhov
2022-04-27 10:30:09 +03:00
committed by teamcity
parent d4d45a8410
commit 73be9d0a20
5 changed files with 14 additions and 13 deletions
@@ -583,7 +583,11 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() {
for (variableWithConstraints in candidate.system.notFixedTypeVariables.values) {
val upperTypes = variableWithConstraints.constraints.extractUpperTypesToCheckIntersectionEmptiness()
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
// TODO: consider reporting errors on bounded type variables by incompatible types but with other lower constraints
if (
variableWithConstraints.constraints.none { it.kind.isLower() }
&& upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()
) {
sink.yieldDiagnostic(
@Suppress("UNCHECKED_CAST")
InferredEmptyIntersectionDiagnostic(
@@ -892,7 +892,11 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
for (variableWithConstraints in getSystem().getBuilder().currentStorage().notFixedTypeVariables.values) {
val upperTypes = variableWithConstraints.constraints.extractUpperTypesToCheckIntersectionEmptiness()
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
// TODO: consider reporting errors on bounded type variables by incompatible types but with other lower constraints
if (
variableWithConstraints.constraints.none { it.kind.isLower() }
&& upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()
) {
val isInferredEmptyIntersectionForbidden =
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
@@ -1,9 +0,0 @@
// WITH_STDLIB
fun expandMaskConditionsAndUpdateVariableNodes(validOffsets: Collection<Int>) {}
fun main(x: List<Int>, y: Int) {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>expandMaskConditionsAndUpdateVariableNodes<!>(
x.mapTo(mutableSetOf()) { y }
)
}
@@ -1,9 +1,10 @@
// FIR_IDENTICAL
// WITH_STDLIB
fun expandMaskConditionsAndUpdateVariableNodes(validOffsets: Collection<Int>) {}
fun main(x: List<Int>, y: Int) {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>expandMaskConditionsAndUpdateVariableNodes<!>(
expandMaskConditionsAndUpdateVariableNodes(
x.mapTo(mutableSetOf()) { y }
)
}
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.types
enum class EmptyIntersectionTypeKind { NOT_EMPTY_INTERSECTION, MULTIPLE_CLASSES } // TODO: add `SINGLE_FINAL_CLASS` later
// TODO: add `SINGLE_FINAL_CLASS` later to report warnings
enum class EmptyIntersectionTypeKind { NOT_EMPTY_INTERSECTION, MULTIPLE_CLASSES }
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean = this == EmptyIntersectionTypeKind.MULTIPLE_CLASSES