Skip to content

Commit e8f7a71

Browse files
committed
[CSBindings] Update static member lookup to utilize new isDelayed API
1 parent 88654b2 commit e8f7a71

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

include/swift/Sema/CSFix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,10 @@ class AllowInvalidStaticMemberRefOnProtocolMetatype final
23252325
return "allow invalid static member reference on a protocol metatype";
23262326
}
23272327

2328+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
2329+
return diagnose(*commonFixes.front().first);
2330+
}
2331+
23282332
bool diagnose(const Solution &solution, bool asNote = false) const override;
23292333

23302334
static AllowInvalidStaticMemberRefOnProtocolMetatype *

lib/Sema/CSBindings.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ bool PotentialBinding::isViableForJoin() const {
5757
}
5858

5959
bool PotentialBindings::isDelayed() const {
60+
if (auto *locator = TypeVar->getImpl().getLocator()) {
61+
if (locator->isLastElement<LocatorPathElt::MemberRefBase>()) {
62+
// If first binding is a "fallback" to a protocol type,
63+
// it means that this type variable should be delayed
64+
// until it either gains more contextual information, or
65+
// there are no other type variables to attempt to make
66+
// forward progress.
67+
if (Bindings.empty())
68+
return true;
69+
70+
71+
if (Bindings[0].BindingType->is<ProtocolType>())
72+
return true;
73+
}
74+
75+
// Since force unwrap preserves l-valueness, resulting
76+
// type variable has to be delayed until either l-value
77+
// binding becomes available or there are no other
78+
// variables to attempt.
79+
if (locator->directlyAt<ForceValueExpr>() &&
80+
TypeVar->getImpl().canBindToLValue()) {
81+
return llvm::none_of(Bindings, [](const PotentialBinding &binding) {
82+
return binding.BindingType->is<LValueType>();
83+
});
84+
}
85+
}
86+
6087
if (isHole()) {
6188
auto *locator = TypeVar->getImpl().getLocator();
6289
assert(locator && "a hole without locator?");
@@ -98,19 +125,6 @@ bool PotentialBindings::isDelayed() const {
98125
});
99126
}
100127

101-
if (auto *locator = TypeVar->getImpl().getLocator()) {
102-
// Since force unwrap preserves l-valueness, resulting
103-
// type variable has to be delayed until either l-value
104-
// binding becomes available or there are no other
105-
// variables to attempt.
106-
if (locator->directlyAt<ForceValueExpr>() &&
107-
TypeVar->getImpl().canBindToLValue()) {
108-
return llvm::none_of(Bindings, [](const PotentialBinding &binding) {
109-
return binding.BindingType->is<LValueType>();
110-
});
111-
}
112-
}
113-
114128
return !DelayedBy.empty();
115129
}
116130

@@ -440,8 +454,6 @@ void PotentialBindings::finalize(
440454
addPotentialBinding(
441455
{protocolTy, AllowedBindingKind::Exact, constraint});
442456
}
443-
444-
FullyBound = true;
445457
}
446458
}
447459

0 commit comments

Comments
 (0)