Skip to content

Commit 84d90ab

Browse files
committed
[sil-verifier] Each archetype occurring in the substitutions list should belong to the current function.
1 parent b6494f6 commit 84d90ab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static llvm::cl::opt<bool> SkipUnreachableMustBeLastErrors(
6060

6161
/// Returns true if A is an opened existential type or is equal to an
6262
/// archetype from F's generic context.
63-
static bool isArchetypeValidInFunction(ArchetypeType *A, SILFunction *F) {
63+
static bool isArchetypeValidInFunction(ArchetypeType *A, const SILFunction *F) {
6464
if (!A->getOpenedExistentialType().isNull())
6565
return true;
6666

@@ -825,6 +825,19 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
825825
require(fnTy->isPolymorphic(),
826826
"callee of apply with substitutions must be polymorphic");
827827

828+
// Each archetype occurring in the substitutions list should belong to the
829+
// current function.
830+
for (auto sub : subs) {
831+
sub.getReplacement()->getCanonicalType().visit([&](CanType t) {
832+
auto A = dyn_cast<ArchetypeType>(t);
833+
if (!A)
834+
return;
835+
require(isArchetypeValidInFunction(A, &F),
836+
"Replacment type of a substitution contains an ArchetypeType "
837+
"that does not exist in the Caller's generic param list.");
838+
});
839+
}
840+
828841
// Apply the substitutions.
829842
return fnTy->substGenericArgs(F.getModule(), subs);
830843
}

0 commit comments

Comments
 (0)