@@ -197,21 +197,21 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
197
197
// have to look through other elements that are generated from an argument
198
198
// conversion such as GenericArgument for an optional-to-optional conversion,
199
199
// and OptionalPayload for a value-to-optional conversion.
200
- auto applyArgElt =
200
+ auto applyArgEltIter =
201
201
std::find_if (path.rbegin (), path.rend (), [](LocatorPathElt elt) {
202
- return elt.getKind () == ConstraintLocator ::ApplyArgToParam;
202
+ return elt.is <LocatorPathElt ::ApplyArgToParam>() ;
203
203
});
204
204
205
- if (applyArgElt == path.rend ())
205
+ if (applyArgEltIter == path.rend ())
206
206
return None;
207
207
208
- assert (std::find_if (applyArgElt + 1 , path.rend (), [](LocatorPathElt elt) {
208
+ assert (std::find_if (applyArgEltIter + 1 , path.rend (), [](LocatorPathElt elt) {
209
209
return elt.getKind () == ConstraintLocator::ApplyArgToParam;
210
210
}) == path.rend () && " Multiple ApplyArgToParam components?" );
211
211
212
212
// Form a new locator that ends at the apply-arg-to-param element, and
213
213
// simplify it to get the full argument expression.
214
- auto argPath = path.drop_back (applyArgElt - path.rbegin ());
214
+ auto argPath = path.drop_back (applyArgEltIter - path.rbegin ());
215
215
auto *argLocator = cs.getConstraintLocator (
216
216
anchor, argPath, ConstraintLocator::getSummaryFlagsForPath (argPath));
217
217
@@ -271,8 +271,9 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
271
271
fnInterfaceType = resolveInterfaceType (rawFnType);
272
272
}
273
273
274
- auto argIdx = applyArgElt->getArgIdx ();
275
- auto paramIdx = applyArgElt->getParamIdx ();
274
+ auto applyArgElt = applyArgEltIter->castTo <LocatorPathElt::ApplyArgToParam>();
275
+ auto argIdx = applyArgElt.getArgIdx ();
276
+ auto paramIdx = applyArgElt.getParamIdx ();
276
277
277
278
return FunctionArgApplyInfo (argExpr, argIdx, getType (argExpr), paramIdx,
278
279
fnInterfaceType, fnType, callee);
@@ -331,11 +332,10 @@ ProtocolConformance *RequirementFailure::getConformanceForConditionalReq(
331
332
auto &cs = getConstraintSystem ();
332
333
auto path = locator->getPath ();
333
334
assert (!path.empty ());
335
+ assert (path.back ().is <LocatorPathElt::AnyRequirement>());
334
336
335
- if (!path.back ().isConditionalRequirement ()) {
336
- assert (path.back ().isTypeParameterRequirement ());
337
+ if (!path.back ().isConditionalRequirement ())
337
338
return nullptr ;
338
- }
339
339
340
340
auto *typeReqLoc = getConstraintLocator (getRawAnchor (), path.drop_back ());
341
341
@@ -414,8 +414,8 @@ GenericSignature *RequirementFailure::getSignature(ConstraintLocator *locator) {
414
414
auto path = locator->getPath ();
415
415
for (auto iter = path.rbegin (); iter != path.rend (); ++iter) {
416
416
const auto &elt = *iter;
417
- if (elt. getKind () == ConstraintLocator ::OpenedGeneric)
418
- return elt. getGenericSignature ();
417
+ if (auto genericElt = elt. getAs <LocatorPathElt ::OpenedGeneric>() )
418
+ return genericElt-> getSignature ();
419
419
}
420
420
421
421
llvm_unreachable (" Type requirement failure should always have signature" );
@@ -783,11 +783,9 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseAsError() {
783
783
GenericTypeParamType *paramTy = nullptr ;
784
784
785
785
auto path = getLocator ()->getPath ();
786
- if (!path.empty ()) {
787
- auto &last = path.back ();
788
- if (last.getKind () == ConstraintLocator::GenericParameter)
789
- paramTy = last.getGenericParameter ();
790
- }
786
+ if (!path.empty ())
787
+ if (auto gpElt = path.back ().getAs <LocatorPathElt::GenericParameter>())
788
+ paramTy = gpElt->getType ();
791
789
792
790
if (paramTy) {
793
791
emitDiagnostic (anchor->getLoc (), diag::converting_noescape_to_type,
@@ -1257,13 +1255,12 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
1257
1255
diagExpr = argTuple->getElement (0 );
1258
1256
} else if (getLocator ()->getPath ().size () > 0 ) {
1259
1257
auto lastPathElement = getLocator ()->getPath ().back ();
1260
- assert (lastPathElement.getKind () ==
1261
- ConstraintLocator::PathElementKind::ApplyArgToParam);
1258
+ auto argElt = lastPathElement.castTo <LocatorPathElt::ApplyArgToParam>();
1262
1259
1263
1260
subElementDiagID = diag::cannot_pass_rvalue_inout_subelement;
1264
1261
rvalueDiagID = diag::cannot_pass_rvalue_inout;
1265
1262
if (auto argTuple = dyn_cast<TupleExpr>(argExpr))
1266
- diagExpr = argTuple->getElement (lastPathElement .getArgIdx ());
1263
+ diagExpr = argTuple->getElement (argElt .getArgIdx ());
1267
1264
else if (auto parens = dyn_cast<ParenExpr>(argExpr))
1268
1265
diagExpr = parens->getSubExpr ();
1269
1266
} else {
@@ -1824,7 +1821,7 @@ AssignmentFailure::getMemberRef(ConstraintLocator *locator) const {
1824
1821
auto paramTy = fnType->getParams ()[0 ].getPlainType ();
1825
1822
auto keyPath = paramTy->getAnyNominal ();
1826
1823
auto memberLoc = cs.getConstraintLocator (
1827
- locator, LocatorPathElt::getKeyPathDynamicMember (keyPath));
1824
+ locator, LocatorPathElt::KeyPathDynamicMember (keyPath));
1828
1825
1829
1826
auto memberRef = getOverloadChoiceIfAvailable (memberLoc);
1830
1827
return memberRef ? Optional<OverloadChoice>(memberRef->choice ) : None;
@@ -2412,8 +2409,7 @@ bool AutoClosureForwardingFailure::diagnoseAsError() {
2412
2409
auto path = getLocator ()->getPath ();
2413
2410
assert (!path.empty ());
2414
2411
2415
- auto &last = path.back ();
2416
- assert (last.getKind () == ConstraintLocator::ApplyArgToParam);
2412
+ auto last = path.back ().castTo <LocatorPathElt::ApplyArgToParam>();
2417
2413
2418
2414
// We need a raw anchor here because `getAnchor()` is simplified
2419
2415
// to the argument expression.
@@ -3577,8 +3573,8 @@ bool KeyPathSubscriptIndexHashableFailure::diagnoseAsError() {
3577
3573
if (locator->isKeyPathSubscriptComponent ()) {
3578
3574
auto *KPE = cast<KeyPathExpr>(anchor);
3579
3575
for (auto &elt : locator->getPath ()) {
3580
- if (elt.isKeyPathComponent ()) {
3581
- loc = KPE->getComponents ()[elt. getKeyPathComponentIdx ()].getLoc ();
3576
+ if (auto kpElt = elt.getAs <LocatorPathElt::KeyPathComponent> ()) {
3577
+ loc = KPE->getComponents ()[kpElt-> getIndex ()].getLoc ();
3582
3578
break ;
3583
3579
}
3584
3580
}
@@ -3594,13 +3590,14 @@ SourceLoc InvalidMemberRefInKeyPath::getLoc() const {
3594
3590
3595
3591
if (auto *KPE = dyn_cast<KeyPathExpr>(anchor)) {
3596
3592
auto *locator = getLocator ();
3597
- auto component =
3593
+ auto componentIter =
3598
3594
llvm::find_if (locator->getPath (), [](const LocatorPathElt &elt) {
3599
3595
return elt.isKeyPathComponent ();
3600
3596
});
3601
3597
3602
- assert (component != locator->getPath ().end ());
3603
- return KPE->getComponents ()[component->getKeyPathComponentIdx ()].getLoc ();
3598
+ assert (componentIter != locator->getPath ().end ());
3599
+ auto component = componentIter->castTo <LocatorPathElt::KeyPathComponent>();
3600
+ return KPE->getComponents ()[component.getIndex ()].getLoc ();
3604
3601
}
3605
3602
3606
3603
return anchor->getLoc ();
@@ -3687,9 +3684,11 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
3687
3684
}
3688
3685
3689
3686
if (isa<DictionaryExpr>(getRawAnchor ())) {
3690
- const auto &eltLoc = locator->getPath ().back ();
3687
+ auto path = locator->getPath ();
3688
+ assert (!path.empty ());
3689
+ auto eltLoc = path.back ().castTo <LocatorPathElt::TupleElement>();
3691
3690
3692
- switch (eltLoc.getTupleElementIdx ()) {
3691
+ switch (eltLoc.getIndex ()) {
3693
3692
case 0 : // key
3694
3693
diagnostic.emplace (emitDiagnostic (anchor->getLoc (),
3695
3694
diag::cannot_convert_dict_key, eltType,
0 commit comments