[FE] Don't check intersection emptiness if there were lower constraints
This commit is contained in:
committed by
teamcity
parent
d4d45a8410
commit
73be9d0a20
@@ -583,7 +583,11 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() {
|
|||||||
for (variableWithConstraints in candidate.system.notFixedTypeVariables.values) {
|
for (variableWithConstraints in candidate.system.notFixedTypeVariables.values) {
|
||||||
val upperTypes = variableWithConstraints.constraints.extractUpperTypesToCheckIntersectionEmptiness()
|
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(
|
sink.yieldDiagnostic(
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
InferredEmptyIntersectionDiagnostic(
|
InferredEmptyIntersectionDiagnostic(
|
||||||
|
|||||||
+5
-1
@@ -892,7 +892,11 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
|
|||||||
for (variableWithConstraints in getSystem().getBuilder().currentStorage().notFixedTypeVariables.values) {
|
for (variableWithConstraints in getSystem().getBuilder().currentStorage().notFixedTypeVariables.values) {
|
||||||
val upperTypes = variableWithConstraints.constraints.extractUpperTypesToCheckIntersectionEmptiness()
|
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 =
|
val isInferredEmptyIntersectionForbidden =
|
||||||
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
|
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
|
||||||
|
|
||||||
|
|||||||
-9
@@ -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 }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+2
-1
@@ -1,9 +1,10 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
|
||||||
fun expandMaskConditionsAndUpdateVariableNodes(validOffsets: Collection<Int>) {}
|
fun expandMaskConditionsAndUpdateVariableNodes(validOffsets: Collection<Int>) {}
|
||||||
|
|
||||||
fun main(x: List<Int>, y: Int) {
|
fun main(x: List<Int>, y: Int) {
|
||||||
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>expandMaskConditionsAndUpdateVariableNodes<!>(
|
expandMaskConditionsAndUpdateVariableNodes(
|
||||||
x.mapTo(mutableSetOf()) { y }
|
x.mapTo(mutableSetOf()) { y }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
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
|
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean = this == EmptyIntersectionTypeKind.MULTIPLE_CLASSES
|
||||||
|
|||||||
Reference in New Issue
Block a user