@@ -249,8 +249,7 @@ ValueDecl *RequirementFailure::getDeclRef() const {
249
249
};
250
250
251
251
if (isFromContextualType ())
252
- return getAffectedDeclFromType (
253
- getContextualType (getLocator ()->getAnchor ()));
252
+ return getAffectedDeclFromType (getContextualType (getRawAnchor ()));
254
253
255
254
if (auto overload = getCalleeOverloadChoiceIfAvailable (getLocator ())) {
256
255
// If there is a declaration associated with this
@@ -2266,8 +2265,7 @@ bool ContextualFailure::diagnoseConversionToNil() const {
2266
2265
emitDiagnostic (*diagnostic, getToType ());
2267
2266
2268
2267
if (CTP == CTP_Initialization) {
2269
- auto *rawAnchor = getRawAnchor ().get <const Expr *>();
2270
- auto *patternTR = getContextualTypeLoc (rawAnchor).getTypeRepr ();
2268
+ auto *patternTR = getContextualTypeLoc (getRawAnchor ()).getTypeRepr ();
2271
2269
if (!patternTR)
2272
2270
return true ;
2273
2271
@@ -2993,8 +2991,7 @@ bool TupleContextualFailure::diagnoseAsError() {
2993
2991
auto purpose = getContextualTypePurpose ();
2994
2992
if (isNumElementsMismatch ())
2995
2993
diagnostic = diag::tuple_types_not_convertible_nelts;
2996
- else if ((purpose == CTP_Initialization) &&
2997
- !getContextualType (getAnchor ().get <const Expr *>()))
2994
+ else if ((purpose == CTP_Initialization) && !getContextualType (getAnchor ()))
2998
2995
diagnostic = diag::tuple_types_not_convertible;
2999
2996
else if (auto diag = getDiagnosticFor (purpose, getToType ()))
3000
2997
diagnostic = *diag;
@@ -3718,7 +3715,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3718
3715
}
3719
3716
3720
3717
// Determine the contextual type of the expression
3721
- Type contextualType = getContextualType (getRawAnchor (). get < const Expr *>() );
3718
+ Type contextualType = getContextualType (getRawAnchor ());
3722
3719
// Try to provide a fix-it that only contains a '.'
3723
3720
if (contextualType && baseTy->isEqual (contextualType)) {
3724
3721
Diag->fixItInsert (loc, " ." );
@@ -3893,9 +3890,8 @@ bool MissingArgumentsFailure::diagnoseAsError() {
3893
3890
// let _: (Int) -> Void = foo
3894
3891
// ```
3895
3892
if (locator->isLastElement <LocatorPathElt::ContextualType>()) {
3896
- emitDiagnostic (
3897
- diag::cannot_convert_initializer_value, getType (anchor),
3898
- resolveType (getContextualType (getAnchor ().get <const Expr *>())));
3893
+ emitDiagnostic (diag::cannot_convert_initializer_value, getType (anchor),
3894
+ resolveType (getContextualType (getAnchor ())));
3899
3895
// TODO: It would be great so somehow point out which arguments are missing.
3900
3896
return true ;
3901
3897
}
@@ -4941,11 +4937,10 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
4941
4937
}
4942
4938
4943
4939
if (locator->isForSequenceElementType ()) {
4944
- auto &cs = getConstraintSystem ();
4945
4940
// If this is a conversion failure related to binding of `for-each`
4946
4941
// statement it has to be diagnosed as pattern match if there are
4947
4942
// holes present in the contextual type.
4948
- if (cs. getContextualTypePurpose (getAnchor (). get < const Expr *> ()) ==
4943
+ if (getContextualTypePurpose (getAnchor ()) ==
4949
4944
ContextualTypePurpose::CTP_ForEachStmt &&
4950
4945
contextualType->hasHole ()) {
4951
4946
diagnostic.emplace (emitDiagnostic (
@@ -5409,7 +5404,7 @@ bool InOutConversionFailure::diagnoseAsError() {
5409
5404
argApplyInfo->getArgType (), argApplyInfo->getParamType ());
5410
5405
} else {
5411
5406
assert (locator->findLast <LocatorPathElt::ContextualType>());
5412
- auto * anchor = getAnchor (). get < const Expr *> ();
5407
+ auto anchor = getAnchor ();
5413
5408
auto contextualType = getContextualType (anchor);
5414
5409
auto purpose = getContextualTypePurpose ();
5415
5410
auto diagnostic = getDiagnosticFor (purpose, contextualType);
0 commit comments