@@ -96,12 +96,8 @@ SourceRange FailureDiagnostic::getSourceRange(TypedNode anchor) {
96
96
}
97
97
}
98
98
99
- Type FailureDiagnostic::getType (Expr *expr, bool wantRValue) const {
100
- return resolveType (S.getType (expr), /* reconstituteSugar=*/ false , wantRValue);
101
- }
102
-
103
- Type FailureDiagnostic::getType (const TypeLoc &loc, bool wantRValue) const {
104
- return resolveType (S.getType (&loc), /* reconstituteSugar=*/ false , wantRValue);
99
+ Type FailureDiagnostic::getType (TypedNode node, bool wantRValue) const {
100
+ return resolveType (S.getType (node), /* reconstituteSugar=*/ false , wantRValue);
105
101
}
106
102
107
103
template <typename ... ArgTypes>
@@ -175,15 +171,17 @@ Type FailureDiagnostic::restoreGenericParameters(
175
171
}
176
172
177
173
Type RequirementFailure::getOwnerType () const {
178
- auto * anchor = getRawAnchor (). get < const Expr *> ();
174
+ auto anchor = getRawAnchor ();
179
175
180
176
// If diagnostic is anchored at assignment expression
181
177
// it means that requirement failure happend while trying
182
178
// to convert source to destination, which means that
183
179
// owner type is actually not an assignment expression
184
180
// itself but its source.
185
- if (auto *assignment = dyn_cast<AssignExpr>(anchor))
186
- anchor = assignment->getSrc ();
181
+ if (auto *E = anchor.dyn_cast <Expr *>()) {
182
+ if (auto *assignment = dyn_cast<AssignExpr>(E))
183
+ anchor = assignment->getSrc ();
184
+ }
187
185
188
186
return getType (anchor)->getInOutObjectType ()->getMetatypeInstanceType ();
189
187
}
@@ -524,8 +522,8 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
524
522
}
525
523
526
524
bool MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef () {
527
- auto * anchor = getRawAnchor (). get < const Expr *> ();
528
- auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(anchor);
525
+ auto anchor = getRawAnchor ();
526
+ auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(anchor. get < const Expr *>() );
529
527
if (!ODRE)
530
528
return false ;
531
529
@@ -994,7 +992,7 @@ bool MissingExplicitConversionFailure::diagnoseAsError() {
994
992
}
995
993
996
994
bool MemberAccessOnOptionalBaseFailure::diagnoseAsError () {
997
- auto * anchor = getAnchor (). get < const Expr *> ();
995
+ auto anchor = getAnchor ();
998
996
auto baseType = getType (anchor);
999
997
bool resultIsOptional = ResultTypeIsOptional;
1000
998
@@ -2017,7 +2015,6 @@ bool ContextualFailure::diagnoseAsError() {
2017
2015
if (isa<OptionalTryExpr>(anchor) || isa<OptionalEvaluationExpr>(anchor)) {
2018
2016
auto objectType = fromType->getOptionalObjectType ();
2019
2017
if (objectType->isEqual (toType)) {
2020
- auto &cs = getConstraintSystem ();
2021
2018
MissingOptionalUnwrapFailure failure (getSolution (), getType (anchor),
2022
2019
toType,
2023
2020
getConstraintLocator (anchor));
@@ -2352,7 +2349,8 @@ bool ContextualFailure::diagnoseCoercionToUnrelatedType() const {
2352
2349
2353
2350
if (auto *coerceExpr = dyn_cast<CoerceExpr>(anchor)) {
2354
2351
auto fromType = getType (coerceExpr->getSubExpr ());
2355
- auto toType = getType (coerceExpr->getCastTypeLoc ());
2352
+ const auto &typeLoc = coerceExpr->getCastTypeLoc ();
2353
+ auto toType = getType (&typeLoc);
2356
2354
2357
2355
auto diagnostic = getDiagnosticFor (CTP_CoerceOperand, toType);
2358
2356
@@ -2513,7 +2511,7 @@ bool ContextualFailure::diagnoseYieldByReferenceMismatch() const {
2513
2511
if (CTP != CTP_YieldByReference)
2514
2512
return false ;
2515
2513
2516
- auto * anchor = getAnchor (). get < const Expr *> ();
2514
+ auto anchor = getAnchor ();
2517
2515
auto exprType = getType (anchor, /* wantRValue=*/ false );
2518
2516
auto contextualType = getToType ();
2519
2517
@@ -3740,8 +3738,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3740
3738
3741
3739
// If the rhs of '~=' is the enum type, a single dot suffixes
3742
3740
// since the type can be inferred
3743
- Type secondArgType =
3744
- cs.getType (binaryExpr->getArg ()->getElement (1 ));
3741
+ Type secondArgType = getType (binaryExpr->getArg ()->getElement (1 ));
3745
3742
if (secondArgType->isEqual (baseTy)) {
3746
3743
Diag->fixItInsert (loc, " ." );
3747
3744
return true ;
@@ -3859,9 +3856,9 @@ bool MissingArgumentsFailure::diagnoseAsError() {
3859
3856
if (isMisplacedMissingArgument (getSolution (), locator))
3860
3857
return false ;
3861
3858
3862
- auto * anchor = getAnchor (). get < const Expr *> ();
3859
+ auto anchor = getAnchor ();
3863
3860
3864
- if (auto *closure = dyn_cast<ClosureExpr>(anchor))
3861
+ if (auto *closure = dyn_cast<ClosureExpr>(anchor. dyn_cast <Expr *>() ))
3865
3862
return diagnoseClosure (closure);
3866
3863
3867
3864
// This is a situation where function type is passed as an argument
@@ -4113,7 +4110,7 @@ bool MissingArgumentsFailure::diagnoseClosure(ClosureExpr *closure) {
4113
4110
locator->isLastElement <LocatorPathElt::ClosureBody>()) {
4114
4111
// Based on the locator we know this this is something like this:
4115
4112
// `let _: () -> ((Int) -> Void) = { return {} }`.
4116
- funcType = getType (getRawAnchor (). get < const Expr *>() )
4113
+ funcType = getType (getRawAnchor ())
4117
4114
->castTo <FunctionType>()
4118
4115
->getResult ()
4119
4116
->castTo <FunctionType>();
@@ -4582,8 +4579,9 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {
4582
4579
bool ExtraneousArgumentsFailure::diagnoseAsError () {
4583
4580
// Simplified anchor would point directly to the
4584
4581
// argument in case of contextual mismatch.
4585
- auto *anchor = getAnchor ().get <const Expr *>();
4586
- if (auto *closure = dyn_cast<ClosureExpr>(anchor)) {
4582
+ auto *anchor = getAnchor ();
4583
+
4584
+ if (auto *closure = dyn_cast<ClosureExpr>(anchor.dyn_cast <Expr *>()) {
4587
4585
auto fnType = ContextualType;
4588
4586
auto params = closure->getParameters ();
4589
4587
@@ -5090,7 +5088,8 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
5090
5088
5091
5089
if (auto *CE =
5092
5090
dyn_cast<ExplicitCastExpr>(getRawAnchor ().get <const Expr *>())) {
5093
- auto castTo = getType (CE->getCastTypeLoc ());
5091
+ const auto &typeLoc = CE->getCastTypeLoc ();
5092
+ auto castTo = getType (&typeLoc);
5094
5093
auto *NTD = castTo->getAnyNominal ();
5095
5094
emitDiagnosticAt (loc, diag::unbound_generic_parameter_cast, GP,
5096
5095
NTD ? NTD->getDeclaredType () : castTo);
@@ -5532,7 +5531,7 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
5532
5531
// If argument is an l-value type and parameter is a pointer type,
5533
5532
// let's match up its element type to the argument to see whether
5534
5533
// it would be appropriate to suggest adding `&`.
5535
- auto * argExpr = getAnchor (). get < const Expr *> ();
5534
+ auto argExpr = getAnchor ();
5536
5535
if (getType (argExpr, /* wantRValue=*/ false )->is <LValueType>()) {
5537
5536
auto elementTy = paramType->getAnyPointerElementType ();
5538
5537
if (elementTy && argType->isEqual (elementTy)) {
@@ -5784,7 +5783,7 @@ bool ExpandArrayIntoVarargsFailure::diagnoseAsNote() {
5784
5783
}
5785
5784
5786
5785
bool ExtraneousCallFailure::diagnoseAsError () {
5787
- auto * anchor = getAnchor (). get < const Expr *> ();
5786
+ auto anchor = getAnchor ();
5788
5787
auto *locator = getLocator ();
5789
5788
5790
5789
// If this is something like `foo()` where `foo` is a variable
@@ -5813,7 +5812,7 @@ bool ExtraneousCallFailure::diagnoseAsError() {
5813
5812
}
5814
5813
}
5815
5814
5816
- if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor)) {
5815
+ if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor. dyn_cast <Expr *>() )) {
5817
5816
auto *baseExpr = UDE->getBase ();
5818
5817
auto *call = cast<CallExpr>(getRawAnchor ().get <const Expr *>());
5819
5818
0 commit comments