[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 /// This should only be used when resolving/validating where clauses in
/// protocols. /// protocols.
class ProtocolRequirementTypeResolver : public GenericTypeResolver { class ProtocolRequirementTypeResolver : public GenericTypeResolver {
ProtocolDecl *Proto;
public: public:
explicit ProtocolRequirementTypeResolver() {} explicit ProtocolRequirementTypeResolver(ProtocolDecl *proto)
: Proto(proto) {}
virtual Type resolveGenericTypeParamType(GenericTypeParamType *gp); virtual Type resolveGenericTypeParamType(GenericTypeParamType *gp);

View File

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

View File

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