@@ -34,7 +34,7 @@ using namespace constraints;
34
34
35
35
ConstraintFix::~ConstraintFix () {}
36
36
37
- Expr * ConstraintFix::getAnchor () const { return getLocator ()->getAnchor (); }
37
+ TypedNode ConstraintFix::getAnchor () const { return getLocator ()->getAnchor (); }
38
38
39
39
void ConstraintFix::print (llvm::raw_ostream &Out) const {
40
40
Out << " [fix: " ;
@@ -135,10 +135,10 @@ CoerceToCheckedCast *CoerceToCheckedCast::attempt(ConstraintSystem &cs,
135
135
if (fromType->hasTypeVariable () || toType->hasTypeVariable ())
136
136
return nullptr ;
137
137
138
- auto *expr = locator->getAnchor ();
139
- if (auto *assignExpr = dyn_cast <AssignExpr>(expr ))
140
- expr = assignExpr->getSrc ();
141
- auto *coerceExpr = dyn_cast <CoerceExpr>(expr );
138
+ auto anchor = locator->getAnchor ();
139
+ if (auto *assignExpr = getAsExpr <AssignExpr>(anchor ))
140
+ anchor = assignExpr->getSrc ();
141
+ auto *coerceExpr = getAsExpr <CoerceExpr>(anchor );
142
142
if (!coerceExpr)
143
143
return nullptr ;
144
144
@@ -189,7 +189,8 @@ bool MissingConformance::diagnose(const Solution &solution, bool asNote) const {
189
189
190
190
if (IsContextual) {
191
191
auto &cs = solution.getConstraintSystem ();
192
- auto context = cs.getContextualTypePurpose (locator->getAnchor ());
192
+ auto context =
193
+ cs.getContextualTypePurpose (locator->getAnchor ().get <const Expr *>());
193
194
MissingContextualConformanceFailure failure (
194
195
solution, context, NonConformingType, ProtocolType, locator);
195
196
return failure.diagnose (asNote);
@@ -264,7 +265,7 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
264
265
locator->isLastElement <LocatorPathElt::FunctionArgument>());
265
266
266
267
auto &cs = solution.getConstraintSystem ();
267
- auto *anchor = locator->getAnchor ();
268
+ auto *anchor = locator->getAnchor (). get < const Expr *>() ;
268
269
auto contextualType = cs.getContextualType (anchor);
269
270
auto exprType = cs.getType (anchor);
270
271
return std::make_tuple (cs.getContextualTypePurpose (anchor), exprType,
@@ -273,15 +274,15 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
273
274
return std::make_tuple (CTP_CallArgument,
274
275
argApplyInfo->getArgType (),
275
276
argApplyInfo->getParamType ());
276
- } else if (auto *coerceExpr = dyn_cast <CoerceExpr>(locator->getAnchor ())) {
277
+ } else if (auto *coerceExpr = getAsExpr <CoerceExpr>(locator->getAnchor ())) {
277
278
return std::make_tuple (CTP_CoerceOperand,
278
279
solution.getType (coerceExpr->getSubExpr ()),
279
280
solution.getType (coerceExpr));
280
- } else if (auto *assignExpr = dyn_cast <AssignExpr>(locator->getAnchor ())) {
281
+ } else if (auto *assignExpr = getAsExpr <AssignExpr>(locator->getAnchor ())) {
281
282
return std::make_tuple (CTP_AssignSource,
282
283
solution.getType (assignExpr->getSrc ()),
283
284
solution.getType (assignExpr->getDest ()));
284
- } else if (auto *call = dyn_cast <CallExpr>(locator->getAnchor ())) {
285
+ } else if (auto *call = getAsExpr <CallExpr>(locator->getAnchor ())) {
285
286
assert (isa<TypeExpr>(call->getFn ()));
286
287
return std::make_tuple (
287
288
CTP_Initialization,
@@ -313,7 +314,8 @@ bool AllowTupleTypeMismatch::coalesceAndDiagnose(
313
314
Type toType;
314
315
315
316
if (getFromType ()->is <TupleType>() && getToType ()->is <TupleType>()) {
316
- purpose = cs.getContextualTypePurpose (locator->getAnchor ());
317
+ purpose =
318
+ cs.getContextualTypePurpose (locator->getAnchor ().get <const Expr *>());
317
319
fromType = getFromType ();
318
320
toType = getToType ();
319
321
} else if (auto contextualTypeInfo =
@@ -500,8 +502,9 @@ DefineMemberBasedOnUse::diagnoseForAmbiguity(CommonFixesArray commonFixes) const
500
502
concreteBaseType = baseType;
501
503
502
504
if (concreteBaseType->getCanonicalType () != baseType->getCanonicalType ()) {
503
- getConstraintSystem ().getASTContext ().Diags .diagnose (getAnchor ()->getLoc (),
504
- diag::unresolved_member_no_inference, Name);
505
+ auto &DE = getConstraintSystem ().getASTContext ().Diags ;
506
+ DE.diagnose (getLoc (getAnchor ()), diag::unresolved_member_no_inference,
507
+ Name);
505
508
return true ;
506
509
}
507
510
}
@@ -655,7 +658,7 @@ bool RemoveExtraneousArguments::diagnose(const Solution &solution,
655
658
656
659
bool RemoveExtraneousArguments::isMinMaxNameShadowing (
657
660
ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
658
- auto *anchor = dyn_cast_or_null <CallExpr>(locator.getAnchor ());
661
+ auto *anchor = getAsExpr <CallExpr>(locator.getAnchor ());
659
662
if (!anchor)
660
663
return false ;
661
664
@@ -1001,7 +1004,9 @@ IgnoreContextualType *IgnoreContextualType::create(ConstraintSystem &cs,
1001
1004
bool IgnoreAssignmentDestinationType::diagnose (const Solution &solution,
1002
1005
bool asNote) const {
1003
1006
auto &cs = getConstraintSystem ();
1004
- auto *AE = cast<AssignExpr>(getAnchor ());
1007
+ auto *AE = getAsExpr<AssignExpr>(getAnchor ());
1008
+
1009
+ assert (AE);
1005
1010
1006
1011
// Let's check whether this is a situation of chained assignment where
1007
1012
// one of the steps in the chain is an assignment to self e.g.
0 commit comments