Skip to content

Commit 0bf65f1

Browse files
authored
Verify that a GenericTypeParamDecl's depth and index are correct (#20100)
(with respect to the containing GenericParamList)
1 parent 908ce05 commit 0bf65f1

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
@@ -2738,6 +2738,37 @@ class Verifier : public ASTWalker {
27382738
verifyCheckedBase(nominal);
27392739
}
27402740

2741+
void verifyCheckedAlways(GenericTypeParamDecl *GTPD) {
2742+
PrettyStackTraceDecl debugStack("verifying GenericTypeParamDecl", GTPD);
2743+
2744+
const DeclContext *DC = GTPD->getDeclContext();
2745+
if (!GTPD->getDeclContext()->isInnermostContextGeneric()) {
2746+
Out << "DeclContext of GenericTypeParamDecl does not have "
2747+
"generic params";
2748+
abort();
2749+
}
2750+
2751+
GenericParamList *paramList =
2752+
static_cast<const GenericContext *>(DC)->getGenericParams();
2753+
if (!paramList) {
2754+
Out << "DeclContext of GenericTypeParamDecl does not have "
2755+
"generic params";
2756+
abort();
2757+
}
2758+
2759+
if (paramList->size() <= GTPD->getIndex() ||
2760+
paramList->getParams()[GTPD->getIndex()] != GTPD) {
2761+
Out << "GenericTypeParamDecl has incorrect index";
2762+
abort();
2763+
}
2764+
if (paramList->getDepth() != GTPD->getDepth()) {
2765+
Out << "GenericTypeParamDecl has incorrect depth";
2766+
abort();
2767+
}
2768+
2769+
verifyCheckedBase(GTPD);
2770+
}
2771+
27412772
void verifyChecked(ExtensionDecl *ext) {
27422773
// Make sure that the protocol conformances are complete.
27432774
for (auto conformance : ext->getLocalConformances()) {

0 commit comments

Comments
 (0)