@@ -166,20 +166,29 @@ class RequirementFailure : public FailureDiagnostic {
166166 using DiagInReference = Diag<DescriptiveDeclKind, DeclName, Type, Type, Type>;
167167 using DiagAsNote = Diag<Type, Type, Type, Type, StringRef>;
168168
169+ // / If this failure associated with one of the conditional requirements,
170+ // / this field would represent conformance where requirement comes from.
171+ const ProtocolConformance *Conformance = nullptr ;
172+
173+ // / The source of the requirement, if available. One exception
174+ // / is failure associated with conditional requirement where
175+ // / underlying conformance is specialized.
176+ const GenericSignature *Signature;
177+
169178 const ValueDecl *AffectedDecl;
170179 // / If possible, find application expression associated
171180 // / with current generic requirement failure, that helps
172181 // / to diagnose failures related to arguments.
173182 const ApplyExpr *Apply = nullptr ;
174183
175- // / If this failure associated with one of the conditional requirements.
176- bool IsConditional = false ;
177-
178184public:
179185 RequirementFailure (ConstraintSystem &cs, Expr *expr, RequirementKind kind,
180186 ConstraintLocator *locator)
181- : FailureDiagnostic(expr, cs, locator), AffectedDecl(getDeclRef()) {
187+ : FailureDiagnostic(expr, cs, locator),
188+ Conformance (getConformanceForConditionalReq(locator)),
189+ Signature(getSignature(locator)), AffectedDecl(getDeclRef()) {
182190 assert (locator);
191+ assert (isConditional () || Signature);
183192 assert (AffectedDecl);
184193
185194 auto path = locator->getPath ();
@@ -190,8 +199,6 @@ class RequirementFailure : public FailureDiagnostic {
190199 last.isConditionalRequirement ());
191200 assert (static_cast <RequirementKind>(last.getValue2 ()) == kind);
192201
193- IsConditional = last.isConditionalRequirement ();
194-
195202 // It's possible sometimes not to have no base expression.
196203 if (!expr)
197204 return ;
@@ -227,11 +234,7 @@ class RequirementFailure : public FailureDiagnostic {
227234
228235protected:
229236 // / Determine whether this is a conditional requirement failure.
230- bool isConditional () const { return IsConditional; }
231-
232- // / If this is a failure in condition requirement, retrieve
233- // / conformance information.
234- ProtocolConformanceRef getConformanceRef () const ;
237+ bool isConditional () const { return bool (Conformance); }
235238
236239 // / Retrieve declaration contextual where current
237240 // / requirement has been introduced.
@@ -268,11 +271,19 @@ class RequirementFailure : public FailureDiagnostic {
268271 // / Retrieve declaration associated with failing generic requirement.
269272 ValueDecl *getDeclRef () const ;
270273
274+ // / Retrieve generic signature where this parameter originates from.
275+ GenericSignature *getSignature (ConstraintLocator *locator);
276+
271277 void emitRequirementNote (const Decl *anchor, Type lhs, Type rhs) const ;
272278
273279 // / Determine whether given declaration represents a static
274280 // / or instance property/method, excluding operators.
275281 static bool isStaticOrInstanceMember (const ValueDecl *decl);
282+
283+ // / If this is a failure in conditional requirement, retrieve
284+ // / conformance information.
285+ ProtocolConformance *
286+ getConformanceForConditionalReq (ConstraintLocator *locator);
276287};
277288
278289// / Diagnostics for failed conformance checks originating from
0 commit comments