mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location could bw inferred from a body of a multi-statement closure (when inference is enabled), so we need to give closure a chance to run before attemtping a hole for such positions in diagnostic mode.
This commit is contained in:
@@ -338,6 +338,14 @@ public:
|
||||
|
||||
TypeVariableType *getTypeVariable() const { return Info.TypeVar; }
|
||||
|
||||
/// Check whether this binding set belongs to a type variable
|
||||
/// that represents a result type of a closure.
|
||||
bool forClosureResult() const;
|
||||
|
||||
/// Check whether this binding set belongs to a type variable
|
||||
/// that represents a generic parameter.
|
||||
bool forGenericParameter() const;
|
||||
|
||||
bool canBeNil() const;
|
||||
|
||||
/// If this type variable doesn't have any viable bindings, or
|
||||
|
||||
@@ -25,6 +25,14 @@ using namespace swift;
|
||||
using namespace constraints;
|
||||
using namespace inference;
|
||||
|
||||
bool BindingSet::forClosureResult() const {
|
||||
return Info.TypeVar->getImpl().isClosureResultType();
|
||||
}
|
||||
|
||||
bool BindingSet::forGenericParameter() const {
|
||||
return bool(Info.TypeVar->getImpl().getGenericParameter());
|
||||
}
|
||||
|
||||
bool BindingSet::canBeNil() const {
|
||||
auto &ctx = CS.getASTContext();
|
||||
return Literals.count(
|
||||
|
||||
@@ -345,6 +345,19 @@ StepResult ComponentStep::take(bool prevFailed) {
|
||||
auto *disjunction = CS.selectDisjunction();
|
||||
auto bestBindings = CS.determineBestBindings();
|
||||
|
||||
if (CS.shouldAttemptFixes()) {
|
||||
if ((bestBindings &&
|
||||
(bestBindings->forClosureResult() ||
|
||||
bestBindings->forGenericParameter()) &&
|
||||
bestBindings->isHole()) &&
|
||||
!disjunction) {
|
||||
if (auto *conjunction = CS.selectConjunction()) {
|
||||
return suspend(
|
||||
std::make_unique<ConjunctionStep>(CS, conjunction, Solutions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestBindings &&
|
||||
(!disjunction || bestBindings->favoredOverDisjunction(disjunction))) {
|
||||
// Produce a type variable step.
|
||||
|
||||
Reference in New Issue
Block a user