Skip to content

Commit 026b51b

Browse files
committed
[ConstraintLocator] Add a isFirstElement helper function
1 parent 7faf378 commit 026b51b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ bool ConstraintLocator::isForOptionalTry() const {
249249
}
250250

251251
bool ConstraintLocator::isForFunctionBuilderBodyResult() const {
252-
auto elt = getFirstElementAs<LocatorPathElt::FunctionBuilderBodyResult>();
253-
return elt.hasValue();
252+
return isFirstElement<LocatorPathElt::FunctionBuilderBodyResult>();
254253
}
255254

256255
GenericTypeParamType *ConstraintLocator::getGenericParameter() const {

lib/Sema/ConstraintLocator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,14 @@ class ConstraintLocator : public llvm::FoldingSetNode {
384384
return anchor && isa<E>(anchor) && getPath().empty();
385385
}
386386

387+
/// Check whether the first element in the path of this locator (if any)
388+
/// is a given \c LocatorPathElt subclass.
389+
template <class T>
390+
bool isFirstElement() const {
391+
auto path = getPath();
392+
return !path.empty() && path.front().is<T>();
393+
}
394+
387395
/// Attempts to cast the first path element of the locator to a specific
388396
/// \c LocatorPathElt subclass, returning \c None if either unsuccessful or
389397
/// the locator has no path elements.

0 commit comments

Comments
 (0)