Skip to content

Commit b1c513d

Browse files
committed
[ConstraintLocator] Add a isFirstElement helper function
1 parent 9baca13 commit b1c513d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/ConstraintLocator.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ bool ConstraintLocator::isForOptionalTry() const {
251251
}
252252

253253
bool ConstraintLocator::isForFunctionBuilderBodyResult() const {
254-
auto elt = getFirstElementAs<LocatorPathElt::FunctionBuilderBodyResult>();
255-
return elt.hasValue();
254+
return isFirstElement<LocatorPathElt::FunctionBuilderBodyResult>();
256255
}
257256

258257
GenericTypeParamType *ConstraintLocator::getGenericParameter() const {

lib/Sema/ConstraintLocator.h

+8
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ class ConstraintLocator : public llvm::FoldingSetNode {
391391
return false;
392392
}
393393

394+
/// Check whether the first element in the path of this locator (if any)
395+
/// is a given \c LocatorPathElt subclass.
396+
template <class T>
397+
bool isFirstElement() const {
398+
auto path = getPath();
399+
return !path.empty() && path.front().is<T>();
400+
}
401+
394402
/// Attempts to cast the first path element of the locator to a specific
395403
/// \c LocatorPathElt subclass, returning \c None if either unsuccessful or
396404
/// the locator has no path elements.

0 commit comments

Comments
 (0)