@@ -864,12 +864,17 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
864
864
return true ;
865
865
}
866
866
867
- bool MissingForcedDowncastFailure::diagnoseAsError () {
868
- auto *expr = getAnchor ();
867
+ Expr *MissingForcedDowncastFailure::getAnchor () const {
868
+ auto *expr = FailureDiagnostic::getAnchor ();
869
+
869
870
if (auto *assignExpr = dyn_cast<AssignExpr>(expr))
870
- expr = assignExpr->getSrc ();
871
+ return assignExpr->getSrc ();
871
872
872
- auto *coerceExpr = cast<CoerceExpr>(expr);
873
+ return expr;
874
+ }
875
+
876
+ bool MissingForcedDowncastFailure::diagnoseAsError () {
877
+ auto *coerceExpr = cast<CoerceExpr>(getAnchor ());
873
878
874
879
auto fromType = getFromType ();
875
880
auto toType = getToType ();
@@ -897,13 +902,21 @@ bool MissingAddressOfFailure::diagnoseAsError() {
897
902
return true ;
898
903
}
899
904
905
+ Expr *MissingExplicitConversionFailure::getAnchor () const {
906
+ auto *anchor = FailureDiagnostic::getAnchor ();
907
+
908
+ if (auto *assign = dyn_cast<AssignExpr>(anchor))
909
+ return assign->getSrc ();
910
+
911
+ if (auto *paren = dyn_cast<ParenExpr>(anchor))
912
+ return paren->getSubExpr ();
913
+
914
+ return anchor;
915
+ }
916
+
900
917
bool MissingExplicitConversionFailure::diagnoseAsError () {
901
918
auto *DC = getDC ();
902
919
auto *anchor = getAnchor ();
903
- if (auto *assign = dyn_cast<AssignExpr>(anchor))
904
- anchor = assign->getSrc ();
905
- if (auto *paren = dyn_cast<ParenExpr>(anchor))
906
- anchor = paren->getSubExpr ();
907
920
908
921
auto fromType = getFromType ();
909
922
auto toType = getToType ();
@@ -915,9 +928,9 @@ bool MissingExplicitConversionFailure::diagnoseAsError() {
915
928
if (!useAs && !TypeChecker::checkedCastMaySucceed (fromType, toType, DC))
916
929
return false ;
917
930
918
- auto *expr = findParentExpr (getAnchor () );
931
+ auto *expr = findParentExpr (anchor );
919
932
if (!expr)
920
- expr = getAnchor () ;
933
+ expr = anchor ;
921
934
922
935
// If we're performing pattern matching,
923
936
// "as" means something completely different...
@@ -3027,13 +3040,17 @@ bool NonOptionalUnwrapFailure::diagnoseAsError() {
3027
3040
return true ;
3028
3041
}
3029
3042
3043
+ Expr *MissingCallFailure::getAnchor () const {
3044
+ auto *anchor = FailureDiagnostic::getAnchor ();
3045
+ if (auto *FVE = dyn_cast<ForceValueExpr>(anchor))
3046
+ return FVE->getSubExpr ();
3047
+ return anchor;
3048
+ }
3049
+
3030
3050
bool MissingCallFailure::diagnoseAsError () {
3031
3051
auto *baseExpr = getAnchor ();
3032
3052
SourceLoc insertLoc = baseExpr->getEndLoc ();
3033
3053
3034
- if (auto *FVE = dyn_cast<ForceValueExpr>(baseExpr))
3035
- baseExpr = FVE->getSubExpr ();
3036
-
3037
3054
// Calls are not yet supported by key path, but it
3038
3055
// is useful to record this fix to diagnose chaining
3039
3056
// where one of the key path components is a method
@@ -3811,6 +3828,13 @@ bool ImplicitInitOnNonConstMetatypeFailure::diagnoseAsError() {
3811
3828
return true ;
3812
3829
}
3813
3830
3831
+ Expr *MissingArgumentsFailure::getAnchor () const {
3832
+ auto *anchor = FailureDiagnostic::getAnchor ();
3833
+ if (auto *captureList = dyn_cast<CaptureListExpr>(anchor))
3834
+ return captureList->getClosureBody ();
3835
+ return anchor;
3836
+ }
3837
+
3814
3838
bool MissingArgumentsFailure::diagnoseAsError () {
3815
3839
auto *locator = getLocator ();
3816
3840
@@ -3827,8 +3851,6 @@ bool MissingArgumentsFailure::diagnoseAsError() {
3827
3851
return false ;
3828
3852
3829
3853
auto *anchor = getAnchor ();
3830
- if (auto *captureList = dyn_cast<CaptureListExpr>(anchor))
3831
- anchor = captureList->getClosureBody ();
3832
3854
3833
3855
if (auto *closure = dyn_cast<ClosureExpr>(anchor))
3834
3856
return diagnoseClosure (closure);
0 commit comments