From 0d393e3fd70b13654b52c1f4ca53674005651d64 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 15 Jan 2020 17:01:44 +0300 Subject: [PATCH] [NI] Update filtering of constraints with equal types Make check for synthetic nullability constraint status before skipping new constraint with nonunique type. --- .../inference/model/MutableConstraintStorage.kt | 6 +++++- ...ughInformationFromNullabilityConstraint.fir.kt | 15 +++++++++++---- ...tEnoughInformationFromNullabilityConstraint.kt | 15 +++++++++++---- ...EnoughInformationFromNullabilityConstraint.txt | 5 ++--- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt index d9418ab1cc2..5e65ed3b553 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt @@ -49,7 +49,11 @@ class MutableVariableWithConstraints( // return new actual constraint, if this constraint is new fun addConstraint(constraint: Constraint): Constraint? { - val previousConstraintWithSameType = constraints.filter { it.typeHashCode == constraint.typeHashCode && it.type == constraint.type } + val previousConstraintWithSameType = constraints.filter { oldConstraint -> + oldConstraint.typeHashCode == constraint.typeHashCode + && oldConstraint.type == constraint.type + && oldConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint + } if (previousConstraintWithSameType.any { previous -> newConstraintIsUseless(previous, constraint) }) return null diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt index d94e0698397..deb087ffcfd 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt @@ -1,9 +1,16 @@ -// !LANGUAGE: +NewInference // !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER fun make(): M? = null fun id(arg: I): I = arg +fun select(vararg args: S): S = TODO() -val v = id( - make() -) +fun test() { + id( + make() + ) + + select(make(), null) + + if (true) make() else TODO() +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.kt b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.kt index 941922ee636..d3623a6b6a3 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.kt @@ -1,9 +1,16 @@ -// !LANGUAGE: +NewInference // !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER fun make(): M? = null fun id(arg: I): I = arg +fun select(vararg args: S): S = TODO() -val v = id( - make() -) +fun test() { + id( + make() + ) + + select(make(), null) + + if (true) make() else TODO() +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.txt b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.txt index ebe772bedaf..390ba5a85d4 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.txt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.txt @@ -1,7 +1,6 @@ package -public val v: [ERROR : Type for id( - make() -)] public fun id(/*0*/ arg: I): I public fun make(): M? +public fun select(/*0*/ vararg args: S /*kotlin.Array*/): S +public fun test(): kotlin.Unit