Skip to content

Verify that a GenericTypeParamDecl's depth and index are correct #20100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,37 @@ class Verifier : public ASTWalker {
verifyCheckedBase(nominal);
}

void verifyCheckedAlways(GenericTypeParamDecl *GTPD) {
PrettyStackTraceDecl debugStack("verifying GenericTypeParamDecl", GTPD);

const DeclContext *DC = GTPD->getDeclContext();
if (!GTPD->getDeclContext()->isInnermostContextGeneric()) {
Out << "DeclContext of GenericTypeParamDecl does not have "
"generic params";
abort();
}

GenericParamList *paramList =
static_cast<const GenericContext *>(DC)->getGenericParams();
if (!paramList) {
Out << "DeclContext of GenericTypeParamDecl does not have "
"generic params";
abort();
}

if (paramList->size() <= GTPD->getIndex() ||
paramList->getParams()[GTPD->getIndex()] != GTPD) {
Out << "GenericTypeParamDecl has incorrect index";
abort();
}
if (paramList->getDepth() != GTPD->getDepth()) {
Out << "GenericTypeParamDecl has incorrect depth";
abort();
}

verifyCheckedBase(GTPD);
}

void verifyChecked(ExtensionDecl *ext) {
// Make sure that the protocol conformances are complete.
for (auto conformance : ext->getLocalConformances()) {
Expand Down