Skip to content

Commit 81afed9

Browse files
committed
[Diagnostics] Add asNote flag to ConstraintFix
1 parent 9f6891a commit 81afed9

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

lib/Sema/CSFix.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,34 @@ std::string ForceDowncast::getName() const {
5252
return name.c_str();
5353
}
5454

55-
bool ForceDowncast::diagnose(Expr *expr) const {
55+
bool ForceDowncast::diagnose(Expr *expr, bool asNote) const {
5656
MissingExplicitConversionFailure failure(expr, getConstraintSystem(),
5757
getLocator(), DowncastTo);
58-
return failure.diagnose();
58+
return failure.diagnose(asNote);
5959
}
6060

6161
ForceDowncast *ForceDowncast::create(ConstraintSystem &cs, Type toType,
6262
ConstraintLocator *locator) {
6363
return new (cs.getAllocator()) ForceDowncast(cs, toType, locator);
6464
}
6565

66-
bool ForceOptional::diagnose(Expr *root) const {
66+
bool ForceOptional::diagnose(Expr *root, bool asNote) const {
6767
MissingOptionalUnwrapFailure failure(root, getConstraintSystem(),
6868
getLocator());
69-
return failure.diagnose();
69+
return failure.diagnose(asNote);
7070
}
7171

7272
ForceOptional *ForceOptional::create(ConstraintSystem &cs,
7373
ConstraintLocator *locator) {
7474
return new (cs.getAllocator()) ForceOptional(cs, locator);
7575
}
7676

77-
bool UnwrapOptionalBase::diagnose(Expr *root) const {
77+
bool UnwrapOptionalBase::diagnose(Expr *root, bool asNote) const {
7878
bool resultIsOptional =
7979
getKind() == FixKind::UnwrapOptionalBaseWithOptionalResult;
8080
MemberAccessOnOptionalBaseFailure failure(
8181
root, getConstraintSystem(), getLocator(), MemberName, resultIsOptional);
82-
return failure.diagnose();
82+
return failure.diagnose(asNote);
8383
}
8484

8585
UnwrapOptionalBase *UnwrapOptionalBase::create(ConstraintSystem &cs,
@@ -95,41 +95,41 @@ UnwrapOptionalBase *UnwrapOptionalBase::createWithOptionalResult(
9595
cs, FixKind::UnwrapOptionalBaseWithOptionalResult, member, locator);
9696
}
9797

98-
bool AddAddressOf::diagnose(Expr *root) const {
98+
bool AddAddressOf::diagnose(Expr *root, bool asNote) const {
9999
MissingAddressOfFailure failure(root, getConstraintSystem(), getLocator());
100-
return failure.diagnose();
100+
return failure.diagnose(asNote);
101101
}
102102

103103
AddAddressOf *AddAddressOf::create(ConstraintSystem &cs,
104104
ConstraintLocator *locator) {
105105
return new (cs.getAllocator()) AddAddressOf(cs, locator);
106106
}
107107

108-
bool TreatRValueAsLValue::diagnose(Expr *root) const {
108+
bool TreatRValueAsLValue::diagnose(Expr *root, bool asNote) const {
109109
RValueTreatedAsLValueFailure failure(getConstraintSystem(), getLocator());
110-
return failure.diagnose();
110+
return failure.diagnose(asNote);
111111
}
112112

113113
TreatRValueAsLValue *TreatRValueAsLValue::create(ConstraintSystem &cs,
114114
ConstraintLocator *locator) {
115115
return new (cs.getAllocator()) TreatRValueAsLValue(cs, locator);
116116
}
117117

118-
bool CoerceToCheckedCast::diagnose(Expr *root) const {
118+
bool CoerceToCheckedCast::diagnose(Expr *root, bool asNote) const {
119119
MissingForcedDowncastFailure failure(root, getConstraintSystem(),
120120
getLocator());
121-
return failure.diagnose();
121+
return failure.diagnose(asNote);
122122
}
123123

124124
CoerceToCheckedCast *CoerceToCheckedCast::create(ConstraintSystem &cs,
125125
ConstraintLocator *locator) {
126126
return new (cs.getAllocator()) CoerceToCheckedCast(cs, locator);
127127
}
128128

129-
bool MarkExplicitlyEscaping::diagnose(Expr *root) const {
129+
bool MarkExplicitlyEscaping::diagnose(Expr *root, bool asNote) const {
130130
NoEscapeFuncToTypeConversionFailure failure(root, getConstraintSystem(),
131131
getLocator(), ConvertTo);
132-
return failure.diagnose();
132+
return failure.diagnose(asNote);
133133
}
134134

135135
MarkExplicitlyEscaping *
@@ -139,9 +139,9 @@ MarkExplicitlyEscaping::create(ConstraintSystem &cs, ConstraintLocator *locator,
139139
MarkExplicitlyEscaping(cs, locator, convertingTo);
140140
}
141141

142-
bool RelabelArguments::diagnose(Expr *root) const {
142+
bool RelabelArguments::diagnose(Expr *root, bool asNote) const {
143143
LabelingFailure failure(getConstraintSystem(), getLocator(), getLabels());
144-
return failure.diagnose();
144+
return failure.diagnose(asNote);
145145
}
146146

147147
RelabelArguments *
@@ -153,10 +153,10 @@ RelabelArguments::create(ConstraintSystem &cs,
153153
return new (mem) RelabelArguments(cs, correctLabels, locator);
154154
}
155155

156-
bool MissingConformance::diagnose(Expr *root) const {
156+
bool MissingConformance::diagnose(Expr *root, bool asNote) const {
157157
MissingConformanceFailure failure(root, getConstraintSystem(), getLocator(),
158158
{NonConformingType, Protocol});
159-
return failure.diagnose();
159+
return failure.diagnose(asNote);
160160
}
161161

162162
MissingConformance *MissingConformance::create(ConstraintSystem &cs, Type type,
@@ -166,10 +166,10 @@ MissingConformance *MissingConformance::create(ConstraintSystem &cs, Type type,
166166
MissingConformance(cs, type, protocol, locator);
167167
}
168168

169-
bool SkipSameTypeRequirement::diagnose(Expr *root) const {
169+
bool SkipSameTypeRequirement::diagnose(Expr *root, bool asNote) const {
170170
SameTypeRequirementFailure failure(root, getConstraintSystem(), LHS, RHS,
171171
getLocator());
172-
return failure.diagnose();
172+
return failure.diagnose(asNote);
173173
}
174174

175175
SkipSameTypeRequirement *
@@ -178,10 +178,10 @@ SkipSameTypeRequirement::create(ConstraintSystem &cs, Type lhs, Type rhs,
178178
return new (cs.getAllocator()) SkipSameTypeRequirement(cs, lhs, rhs, locator);
179179
}
180180

181-
bool SkipSuperclassRequirement::diagnose(Expr *root) const {
181+
bool SkipSuperclassRequirement::diagnose(Expr *root, bool asNote) const {
182182
SuperclassRequirementFailure failure(root, getConstraintSystem(), LHS, RHS,
183183
getLocator());
184-
return failure.diagnose();
184+
return failure.diagnose(asNote);
185185
}
186186

187187
SkipSuperclassRequirement *

lib/Sema/CSFix.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ConstraintFix {
9494

9595
/// Diagnose a failure associated with this fix given
9696
/// root expression and information from constraint system.
97-
virtual bool diagnose(Expr *root) const = 0;
97+
virtual bool diagnose(Expr *root, bool asNote = false) const = 0;
9898

9999
void print(llvm::raw_ostream &Out) const;
100100

@@ -122,7 +122,7 @@ class ForceDowncast final : public ConstraintFix {
122122

123123
public:
124124
std::string getName() const override;
125-
bool diagnose(Expr *root) const override;
125+
bool diagnose(Expr *root, bool asNote = false) const override;
126126

127127
static ForceDowncast *create(ConstraintSystem &cs, Type toType,
128128
ConstraintLocator *locator);
@@ -136,7 +136,7 @@ class ForceOptional final : public ConstraintFix {
136136
public:
137137
std::string getName() const override { return "force optional"; }
138138

139-
bool diagnose(Expr *root) const override;
139+
bool diagnose(Expr *root, bool asNote = false) const override;
140140

141141
static ForceOptional *create(ConstraintSystem &cs,
142142
ConstraintLocator *locator);
@@ -158,7 +158,7 @@ class UnwrapOptionalBase final : public ConstraintFix {
158158
return "unwrap optional base of member lookup";
159159
}
160160

161-
bool diagnose(Expr *root) const override;
161+
bool diagnose(Expr *root, bool asNote = false) const override;
162162

163163
static UnwrapOptionalBase *create(ConstraintSystem &cs, DeclName member,
164164
ConstraintLocator *locator);
@@ -176,7 +176,7 @@ class AddAddressOf final : public ConstraintFix {
176176
public:
177177
std::string getName() const override { return "add address-of"; }
178178

179-
bool diagnose(Expr *root) const override;
179+
bool diagnose(Expr *root, bool asNote = false) const override;
180180

181181
static AddAddressOf *create(ConstraintSystem &cs, ConstraintLocator *locator);
182182
};
@@ -189,7 +189,7 @@ class TreatRValueAsLValue final : public ConstraintFix {
189189
public:
190190
std::string getName() const override { return "treat rvalue as lvalue"; }
191191

192-
bool diagnose(Expr *root) const override;
192+
bool diagnose(Expr *root, bool asNote = false) const override;
193193

194194
static TreatRValueAsLValue *create(ConstraintSystem &cs,
195195
ConstraintLocator *locator);
@@ -204,7 +204,7 @@ class CoerceToCheckedCast final : public ConstraintFix {
204204
public:
205205
std::string getName() const override { return "as to as!"; }
206206

207-
bool diagnose(Expr *root) const override;
207+
bool diagnose(Expr *root, bool asNote = false) const override;
208208

209209
static CoerceToCheckedCast *create(ConstraintSystem &cs,
210210
ConstraintLocator *locator);
@@ -224,7 +224,7 @@ class MarkExplicitlyEscaping final : public ConstraintFix {
224224
public:
225225
std::string getName() const override { return "add @escaping"; }
226226

227-
bool diagnose(Expr *root) const override;
227+
bool diagnose(Expr *root, bool asNote = false) const override;
228228

229229
static MarkExplicitlyEscaping *create(ConstraintSystem &cs,
230230
ConstraintLocator *locator,
@@ -256,7 +256,7 @@ class RelabelArguments final
256256
return {getTrailingObjects<Identifier>(), NumLabels};
257257
}
258258

259-
bool diagnose(Expr *root) const override;
259+
bool diagnose(Expr *root, bool asNote = false) const override;
260260

261261
static RelabelArguments *create(ConstraintSystem &cs,
262262
llvm::ArrayRef<Identifier> correctLabels,
@@ -283,7 +283,7 @@ class MissingConformance final : public ConstraintFix {
283283
return "add missing protocol conformance";
284284
}
285285

286-
bool diagnose(Expr *root) const override;
286+
bool diagnose(Expr *root, bool asNote = false) const override;
287287

288288
static MissingConformance *create(ConstraintSystem &cs, Type type,
289289
ProtocolDecl *protocol,
@@ -305,7 +305,7 @@ class SkipSameTypeRequirement final : public ConstraintFix {
305305
return "skip same-type generic requirement";
306306
}
307307

308-
bool diagnose(Expr *root) const override;
308+
bool diagnose(Expr *root, bool asNote = false) const override;
309309

310310
static SkipSameTypeRequirement *create(ConstraintSystem &cs, Type lhs,
311311
Type rhs, ConstraintLocator *locator);
@@ -326,7 +326,7 @@ class SkipSuperclassRequirement final : public ConstraintFix {
326326
return "skip superclass generic requirement";
327327
}
328328

329-
bool diagnose(Expr *root) const override;
329+
bool diagnose(Expr *root, bool asNote = false) const override;
330330

331331
static SkipSuperclassRequirement *
332332
create(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator);

0 commit comments

Comments
 (0)