[TypeCheck] Bad Self GTPTs from invalid protocols shouldn't crash.

This commit is contained in:
Huon Wilson
2017-02-24 22:55:55 -08:00
parent 644f6df424
commit 76525439d0
3 changed files with 7 additions and 3 deletions

View File

@@ -166,8 +166,11 @@ public:
/// This should only be used when resolving/validating where clauses in
/// protocols.
class ProtocolRequirementTypeResolver : public GenericTypeResolver {
ProtocolDecl *Proto;
public:
explicit ProtocolRequirementTypeResolver() {}
explicit ProtocolRequirementTypeResolver(ProtocolDecl *proto)
: Proto(proto) {}
virtual Type resolveGenericTypeParamType(GenericTypeParamType *gp);

View File

@@ -4348,7 +4348,7 @@ public:
if (auto whereClause = assocType->getTrailingWhereClause()) {
DeclContext *lookupDC = assocType->getDeclContext();
ProtocolRequirementTypeResolver resolver;
ProtocolRequirementTypeResolver resolver(PD);
TypeResolutionOptions options;
for (auto &req : whereClause->getRequirements()) {

View File

@@ -130,7 +130,7 @@ void GenericTypeToArchetypeResolver::recordParamType(ParamDecl *decl, Type type)
Type ProtocolRequirementTypeResolver::resolveGenericTypeParamType(
GenericTypeParamType *gp) {
assert(gp->getDepth() == 0 && gp->getIndex() == 0 &&
assert(gp->isEqual(Proto->getSelfInterfaceType()) &&
"found non-Self-shaped GTPT when resolving protocol requirement");
return gp;
}
@@ -143,6 +143,7 @@ Type ProtocolRequirementTypeResolver::resolveDependentMemberType(
Type ProtocolRequirementTypeResolver::resolveSelfAssociatedType(
Type selfTy, AssociatedTypeDecl *assocType) {
assert(selfTy->isEqual(Proto->getSelfInterfaceType()));
return assocType->getDeclaredInterfaceType();
}