File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -234,18 +234,15 @@ bool ConstraintLocator::isForContextualType() const {
234
234
}
235
235
236
236
bool ConstraintLocator::isForAssignment () const {
237
- auto *anchor = getAnchor ();
238
- return anchor && isa<AssignExpr>(anchor) && getPath ().empty ();
237
+ return directlyAt<AssignExpr>();
239
238
}
240
239
241
240
bool ConstraintLocator::isForCoercion () const {
242
- auto *anchor = getAnchor ();
243
- return anchor && isa<CoerceExpr>(anchor) && getPath ().empty ();
241
+ return directlyAt<CoerceExpr>();
244
242
}
245
243
246
244
bool ConstraintLocator::isForOptionalTry () const {
247
- auto *anchor = getAnchor ();
248
- return anchor && isa<OptionalTryExpr>(anchor) && getPath ().empty ();
245
+ return directlyAt<OptionalTryExpr>();
249
246
}
250
247
251
248
GenericTypeParamType *ConstraintLocator::getGenericParameter () const {
Original file line number Diff line number Diff line change @@ -374,6 +374,12 @@ class ConstraintLocator : public llvm::FoldingSetNode {
374
374
// / Determine whether this locator points to the `try?` expression.
375
375
bool isForOptionalTry () const ;
376
376
377
+ // / Determine whether this locator points directly to a given expression.
378
+ template <class E > bool directlyAt () const {
379
+ auto *anchor = getAnchor ();
380
+ return anchor && isa<E>(anchor) && getPath ().empty ();
381
+ }
382
+
377
383
// / Attempts to cast the first path element of the locator to a specific
378
384
// / \c LocatorPathElt subclass, returning \c None if either unsuccessful or
379
385
// / the locator has no path elements.
You can’t perform that action at this time.
0 commit comments