Skip to content

Commit 872d4c1

Browse files
committed
Verify that a GenericTypeParamDecl's depth and index are correct
(with respect to the containing GenericParamList)
1 parent ca53d0b commit 872d4c1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,37 @@ class Verifier : public ASTWalker {
27152715
verifyCheckedBase(nominal);
27162716
}
27172717

2718+
void verifyCheckedAlways(GenericTypeParamDecl *GTPD) {
2719+
PrettyStackTraceDecl debugStack("verifying GenericTypeParamDecl", GTPD);
2720+
2721+
const DeclContext *DC = GTPD->getDeclContext();
2722+
if (!GTPD->getDeclContext()->isInnermostContextGeneric()) {
2723+
Out << "DeclContext of GenericTypeParamDecl does not have "
2724+
"generic params";
2725+
abort();
2726+
}
2727+
2728+
GenericParamList *paramList =
2729+
static_cast<const GenericContext *>(DC)->getGenericParams();
2730+
if (!paramList) {
2731+
Out << "DeclContext of GenericTypeParamDecl does not have "
2732+
"generic params";
2733+
abort();
2734+
}
2735+
2736+
if (paramList->size() <= GTPD->getIndex() ||
2737+
paramList->getParams()[GTPD->getIndex()] != GTPD) {
2738+
Out << "GenericTypeParamDecl has incorrect index";
2739+
abort();
2740+
}
2741+
if (paramList->getDepth() != GTPD->getDepth()) {
2742+
Out << "GenericTypeParamDecl has incorrect depth";
2743+
abort();
2744+
}
2745+
2746+
verifyCheckedBase(GTPD);
2747+
}
2748+
27182749
void verifyChecked(ExtensionDecl *ext) {
27192750
// Make sure that the protocol conformances are complete.
27202751
for (auto conformance : ext->getLocalConformances()) {

0 commit comments

Comments
 (0)