Skip to content

Commit d1a11cd

Browse files
committed
[ConstraintLocator] Add an accessor to check whether locator points directly at try?
1 parent fd6060b commit d1a11cd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ bool ConstraintLocator::isForCoercion() const {
243243
return anchor && isa<CoerceExpr>(anchor) && getPath().empty();
244244
}
245245

246+
bool ConstraintLocator::isForOptionalTry() const {
247+
auto *anchor = getAnchor();
248+
return anchor && isa<OptionalTryExpr>(anchor) && getPath().empty();
249+
}
250+
246251
GenericTypeParamType *ConstraintLocator::getGenericParameter() const {
247252
// Check whether we have a path that terminates at a generic parameter.
248253
return isForGenericParameter() ?

lib/Sema/ConstraintLocator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ class ConstraintLocator : public llvm::FoldingSetNode {
371371
/// Determine whether this locator points to the coercion expression.
372372
bool isForCoercion() const;
373373

374+
/// Determine whether this locator points to the `try?` expression.
375+
bool isForOptionalTry() const;
376+
374377
/// Attempts to cast the first path element of the locator to a specific
375378
/// \c LocatorPathElt subclass, returning \c None if either unsuccessful or
376379
/// the locator has no path elements.

0 commit comments

Comments
 (0)