20
20
#include " ConstraintSystem.h"
21
21
#include " OverloadChoice.h"
22
22
#include " swift/AST/ASTContext.h"
23
+ #include " swift/AST/ASTNode.h"
23
24
#include " swift/AST/Decl.h"
24
25
#include " swift/AST/DiagnosticEngine.h"
25
26
#include " swift/AST/Expr.h"
@@ -45,7 +46,7 @@ class FailureDiagnostic {
45
46
FailureDiagnostic (const Solution &solution, ConstraintLocator *locator)
46
47
: S(solution), Locator(locator) {}
47
48
48
- FailureDiagnostic (const Solution &solution, TypedNode anchor)
49
+ FailureDiagnostic (const Solution &solution, ASTNode anchor)
49
50
: FailureDiagnostic(solution, solution.getConstraintLocator(anchor)) {}
50
51
51
52
virtual ~FailureDiagnostic ();
@@ -77,13 +78,13 @@ class FailureDiagnostic {
77
78
// / e.g. ambiguity error.
78
79
virtual bool diagnoseAsNote ();
79
80
80
- TypedNode getRawAnchor () const { return Locator->getAnchor (); }
81
+ ASTNode getRawAnchor () const { return Locator->getAnchor (); }
81
82
82
- virtual TypedNode getAnchor () const ;
83
+ virtual ASTNode getAnchor () const ;
83
84
84
85
ConstraintLocator *getLocator () const { return Locator; }
85
86
86
- Type getType (TypedNode node, bool wantRValue = true ) const ;
87
+ Type getType (ASTNode node, bool wantRValue = true ) const ;
87
88
88
89
// / Resolve type variables present in the raw type, if any.
89
90
Type resolveType (Type rawType, bool reconstituteSugar = false ,
@@ -117,17 +118,17 @@ class FailureDiagnostic {
117
118
return S.getConstraintSystem ();
118
119
}
119
120
120
- Type getContextualType (TypedNode anchor) const {
121
+ Type getContextualType (ASTNode anchor) const {
121
122
auto &cs = getConstraintSystem ();
122
123
return cs.getContextualType (anchor);
123
124
}
124
125
125
- TypeLoc getContextualTypeLoc (TypedNode anchor) const {
126
+ TypeLoc getContextualTypeLoc (ASTNode anchor) const {
126
127
auto &cs = getConstraintSystem ();
127
128
return cs.getContextualTypeLoc (anchor);
128
129
}
129
130
130
- ContextualTypePurpose getContextualTypePurpose (TypedNode anchor) const {
131
+ ContextualTypePurpose getContextualTypePurpose (ASTNode anchor) const {
131
132
auto &cs = getConstraintSystem ();
132
133
return cs.getContextualTypePurpose (anchor);
133
134
}
@@ -157,17 +158,17 @@ class FailureDiagnostic {
157
158
}
158
159
159
160
ConstraintLocator *
160
- getConstraintLocator (TypedNode anchor,
161
+ getConstraintLocator (ASTNode anchor,
161
162
ConstraintLocator::PathElement element) const {
162
- return S.getConstraintLocator (anchor. get < const Expr *>() , {element});
163
+ return S.getConstraintLocator (anchor, {element});
163
164
}
164
165
165
166
// / Retrive the constraint locator for the given anchor and
166
167
// / path, uniqued and automatically calculate the summary flags
167
168
ConstraintLocator *getConstraintLocator (
168
- TypedNode anchor,
169
+ ASTNode anchor,
169
170
ArrayRef<ConstraintLocator::PathElement> path = {}) const {
170
- return S.getConstraintLocator (anchor. get < const Expr *>() , path);
171
+ return S.getConstraintLocator (anchor, path);
171
172
}
172
173
173
174
ConstraintLocator *
@@ -247,7 +248,7 @@ class RequirementFailure : public FailureDiagnostic {
247
248
assert (getGenericContext () &&
248
249
" Affected decl not within a generic context?" );
249
250
250
- if (auto *parentExpr = findParentExpr (getRawAnchor ().get <const Expr *>()))
251
+ if (auto *parentExpr = findParentExpr (getRawAnchor ().get <Expr *>()))
251
252
Apply = dyn_cast<ApplyExpr>(parentExpr);
252
253
}
253
254
@@ -490,8 +491,7 @@ class TrailingClosureAmbiguityFailure final : public FailureDiagnostic {
490
491
ArrayRef<OverloadChoice> Choices;
491
492
492
493
public:
493
- TrailingClosureAmbiguityFailure (ArrayRef<Solution> solutions,
494
- TypedNode anchor,
494
+ TrailingClosureAmbiguityFailure (ArrayRef<Solution> solutions, ASTNode anchor,
495
495
ArrayRef<OverloadChoice> choices)
496
496
: FailureDiagnostic(solutions.front(), anchor), Choices(choices) {}
497
497
@@ -504,16 +504,16 @@ class TrailingClosureAmbiguityFailure final : public FailureDiagnostic {
504
504
// / trying to assign something to immutable value, or trying
505
505
// / to access mutating member on immutable base.
506
506
class AssignmentFailure final : public FailureDiagnostic {
507
- const Expr *DestExpr;
507
+ Expr *DestExpr;
508
508
SourceLoc Loc;
509
509
Diag<StringRef> DeclDiagnostic;
510
510
Diag<Type> TypeDiagnostic;
511
511
512
512
public:
513
- AssignmentFailure (const Expr *destExpr, const Solution &solution,
513
+ AssignmentFailure (Expr *destExpr, const Solution &solution,
514
514
SourceLoc diagnosticLoc);
515
515
516
- AssignmentFailure (const Expr *destExpr, const Solution &solution,
516
+ AssignmentFailure (Expr *destExpr, const Solution &solution,
517
517
SourceLoc diagnosticLoc, Diag<StringRef> declDiag,
518
518
Diag<Type> typeDiag)
519
519
: FailureDiagnostic(solution, destExpr), DestExpr(destExpr),
@@ -789,7 +789,7 @@ class MissingExplicitConversionFailure final : public ContextualFailure {
789
789
Type toType, ConstraintLocator *locator)
790
790
: ContextualFailure(solution, fromType, toType, locator) {}
791
791
792
- TypedNode getAnchor () const override ;
792
+ ASTNode getAnchor () const override ;
793
793
794
794
bool diagnoseAsError () override ;
795
795
@@ -950,7 +950,7 @@ class MissingCallFailure final : public FailureDiagnostic {
950
950
MissingCallFailure (const Solution &solution, ConstraintLocator *locator)
951
951
: FailureDiagnostic(solution, locator) {}
952
952
953
- TypedNode getAnchor () const override ;
953
+ ASTNode getAnchor () const override ;
954
954
955
955
bool diagnoseAsError () override ;
956
956
};
@@ -1149,7 +1149,7 @@ class InvalidInitRefFailure : public FailureDiagnostic {
1149
1149
const ConstructorDecl *Init;
1150
1150
SourceRange BaseRange;
1151
1151
1152
- TypedNode getAnchor () const override { return getRawAnchor (); }
1152
+ ASTNode getAnchor () const override { return getRawAnchor (); }
1153
1153
1154
1154
InvalidInitRefFailure (const Solution &solution, Type baseTy,
1155
1155
const ConstructorDecl *init, SourceRange baseRange,
@@ -1243,7 +1243,7 @@ class MissingArgumentsFailure final : public FailureDiagnostic {
1243
1243
assert (!SynthesizedArgs.empty () && " No missing arguments?!" );
1244
1244
}
1245
1245
1246
- TypedNode getAnchor () const override ;
1246
+ ASTNode getAnchor () const override ;
1247
1247
1248
1248
bool diagnoseAsError () override ;
1249
1249
@@ -1268,8 +1268,7 @@ class MissingArgumentsFailure final : public FailureDiagnostic {
1268
1268
// / Gather information associated with expression that represents
1269
1269
// / a call - function, arguments, # of arguments and whether it has
1270
1270
// / a trailing closure.
1271
- std::tuple<Expr *, Expr *, unsigned , bool >
1272
- getCallInfo (TypedNode anchor) const ;
1271
+ std::tuple<Expr *, Expr *, unsigned , bool > getCallInfo (ASTNode anchor) const ;
1273
1272
1274
1273
// / Transform given argument into format suitable for a fix-it
1275
1274
// / text e.g. `[<label>:]? <#<type#>`
@@ -1636,7 +1635,7 @@ class InOutConversionFailure final : public ContextualFailure {
1636
1635
// / _ = S()
1637
1636
// / ```
1638
1637
class MissingGenericArgumentsFailure final : public FailureDiagnostic {
1639
- using Anchor = llvm::PointerUnion<TypeRepr *, const Expr *>;
1638
+ using Anchor = llvm::PointerUnion<TypeRepr *, Expr *>;
1640
1639
1641
1640
SmallVector<GenericTypeParamType *, 4 > Parameters;
1642
1641
@@ -1872,7 +1871,7 @@ class MissingForcedDowncastFailure final : public ContextualFailure {
1872
1871
Type toType, ConstraintLocator *locator)
1873
1872
: ContextualFailure(solution, fromType, toType, locator) {}
1874
1873
1875
- TypedNode getAnchor () const override ;
1874
+ ASTNode getAnchor () const override ;
1876
1875
1877
1876
bool diagnoseAsError () override ;
1878
1877
};
0 commit comments