Skip to content

Commit c9a289e

Browse files
committed
[ConstraintSystem] Add a method to determine whether disjunction represents an operator
1 parent 90354d9 commit c9a289e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,6 +5620,10 @@ void performSyntacticDiagnosticsForTarget(
56205620
/// generic requirement and if so return that type or null type otherwise.
56215621
Type getConcreteReplacementForProtocolSelfType(ValueDecl *member);
56225622

5623+
/// Determine whether given disjunction constraint represents a set
5624+
/// of operator overload choices.
5625+
bool isOperatorDisjunction(Constraint *disjunction);
5626+
56235627
} // end namespace constraints
56245628

56255629
template<typename ...Args>

lib/Sema/ConstraintSystem.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,3 +5689,18 @@ TypeVarBindingProducer::getDefaultBinding(Constraint *constraint) const {
56895689
? binding.withType(OptionalType::get(type))
56905690
: binding;
56915691
}
5692+
5693+
bool constraints::isOperatorDisjunction(Constraint *disjunction) {
5694+
assert(disjunction->getKind() == ConstraintKind::Disjunction);
5695+
5696+
auto choices = disjunction->getNestedConstraints();
5697+
if (choices.empty())
5698+
return false;
5699+
5700+
auto *choice = choices.front();
5701+
if (choice->getKind() != ConstraintKind::BindOverload)
5702+
return false;
5703+
5704+
auto *decl = choice->getOverloadChoice().getDeclOrNull();
5705+
return decl ? decl->isOperator() : false;
5706+
}

0 commit comments

Comments
 (0)