Skip to content

Commit f0e61d9

Browse files
committed
Fix bug in SubstitutionMap::verify(), and add check that concrete conformances match concrete types
1 parent 9e12b37 commit f0e61d9

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ void SubstitutionMap::verify() const {
657657
if (req.getKind() != RequirementKind::Conformance)
658658
continue;
659659

660+
SWIFT_DEFER { ++conformanceIndex; };
660661
auto substType = req.getFirstType().subst(*this);
661662
if (substType->isTypeParameter() ||
662663
substType->is<ArchetypeType>() ||
@@ -677,15 +678,44 @@ void SubstitutionMap::verify() const {
677678
llvm::dbgs() << "SubstitutionMap:\n";
678679
dump(llvm::dbgs());
679680
llvm::dbgs() << "\n";
681+
llvm::dbgs() << "Requirement:\n";
682+
req.dump(llvm::dbgs());
683+
llvm::dbgs() << "\n";
680684
}
681685
assert(conformance.isConcrete() && "Conformance should be concrete");
686+
687+
if (substType->is<UnboundGenericType>())
688+
continue;
689+
690+
auto conformanceTy = conformance.getConcrete()->getType();
691+
if (conformanceTy->hasTypeParameter()
692+
&& !substType->hasTypeParameter()) {
693+
conformanceTy = conformance.getConcrete()->getDeclContext()
694+
->mapTypeIntoContext(conformanceTy);
695+
}
696+
697+
if (!substType->isEqual(conformanceTy)) {
698+
llvm::dbgs() << "Conformance must match concrete replacement type:\n";
699+
substType->dump(llvm::dbgs());
700+
llvm::dbgs() << "Conformance type:\n";
701+
conformance.getConcrete()->getType()->dump(llvm::dbgs());
702+
llvm::dbgs() << "Conformance:\n";
703+
conformance.dump(llvm::dbgs());
704+
llvm::dbgs() << "\n";
705+
llvm::dbgs() << "SubstitutionMap:\n";
706+
dump(llvm::dbgs());
707+
llvm::dbgs() << "\n";
708+
llvm::dbgs() << "Requirement:\n";
709+
req.dump(llvm::dbgs());
710+
llvm::dbgs() << "\n";
711+
}
712+
assert(substType->isEqual(conformanceTy)
713+
&& "conformance should match corresponding type");
682714

683715
if (substType->isExistentialType()) {
684716
assert(isa<SelfProtocolConformance>(conformance.getConcrete()) &&
685717
"Existential type cannot have normal conformance");
686718
}
687-
688-
++conformanceIndex;
689719
}
690720
#endif
691721
}

0 commit comments

Comments
 (0)