File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,27 @@ class ConstraintLocator : public llvm::FoldingSetNode {
502
502
// / Determine whether this locator points to the contextual type.
503
503
bool isForContextualType () const ;
504
504
505
+ // / Attempts to cast the first path element of the locator to a specific
506
+ // / \c LocatorPathElt subclass, returning \c None if either unsuccessful or
507
+ // / the locator has no path elements.
508
+ template <class T >
509
+ Optional<T> getFirstElementAs () const {
510
+ auto path = getPath ();
511
+ if (path.empty ())
512
+ return None;
513
+
514
+ return path[0 ].getAs <T>();
515
+ }
516
+
517
+ // / Casts the first path element of the locator to a specific
518
+ // / \c LocatorPathElt subclass, asserting that it has at least one element.
519
+ template <class T >
520
+ T castFirstElementTo () const {
521
+ auto path = getPath ();
522
+ assert (!path.empty () && " Expected at least one path element!" );
523
+ return path[0 ].castTo <T>();
524
+ }
525
+
505
526
// / Check whether the last element in the path of this locator
506
527
// / is of a given kind.
507
528
bool isLastElement (ConstraintLocator::PathElementKind kind) const ;
You can’t perform that action at this time.
0 commit comments