Skip to content

Commit 86995f7

Browse files
committed
[CSDiagnostics] Add a couple of asserts to RequirementFailure
This will make it slightly easier to spot cases where we've resolved to the wrong affected decl.
1 parent 1bf5631 commit 86995f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ Type RequirementFailure::getOwnerType() const {
310310
const GenericContext *RequirementFailure::getGenericContext() const {
311311
if (auto *genericCtx = AffectedDecl->getAsGenericContext())
312312
return genericCtx;
313-
return AffectedDecl->getDeclContext()->getAsDecl()->getAsGenericContext();
313+
314+
auto parentDecl = AffectedDecl->getDeclContext()->getAsDecl();
315+
if (!parentDecl)
316+
return nullptr;
317+
318+
return parentDecl->getAsGenericContext();
314319
}
315320

316321
const Requirement &RequirementFailure::getRequirement() const {

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ class RequirementFailure : public FailureDiagnostic {
236236
assert(locator);
237237
assert(isConditional() || Signature);
238238
assert(AffectedDecl);
239+
assert(getRequirementDC() &&
240+
"Couldn't find where the requirement came from?");
241+
assert(getGenericContext() &&
242+
"Affected decl not within a generic context?");
239243

240244
auto reqElt = locator->castLastElementTo<LocatorPathElt::AnyRequirement>();
241245
assert(reqElt.getRequirementKind() == kind);

0 commit comments

Comments
 (0)