@@ -4015,128 +4015,6 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
40154015 return resultType;
40164016}
40174017
4018- namespace {
4019-
4020- class UnsupportedProtocolVisitor
4021- : public TypeReprVisitor<UnsupportedProtocolVisitor>, public ASTWalker
4022- {
4023- ASTContext &Ctx;
4024- bool checkStatements;
4025- bool hitTopStmt;
4026-
4027- public:
4028- UnsupportedProtocolVisitor (ASTContext &ctx, bool checkStatements)
4029- : Ctx(ctx), checkStatements(checkStatements), hitTopStmt(false ) { }
4030-
4031- bool walkToTypeReprPre (TypeRepr *T) override {
4032- if (T->isInvalid ())
4033- return false ;
4034- if (auto compound = dyn_cast<CompoundIdentTypeRepr>(T)) {
4035- // Only visit the last component to check, because nested typealiases in
4036- // existentials are okay.
4037- visit (compound->getComponentRange ().back ());
4038- return false ;
4039- }
4040- // Arbitrary protocol constraints are OK on opaque types.
4041- if (isa<OpaqueReturnTypeRepr>(T))
4042- return false ;
4043-
4044- visit (T);
4045- return true ;
4046- }
4047-
4048- std::pair<bool , Stmt*> walkToStmtPre (Stmt *S) override {
4049- if (checkStatements && !hitTopStmt) {
4050- hitTopStmt = true ;
4051- return { true , S };
4052- }
4053-
4054- return { false , S };
4055- }
4056-
4057- bool walkToDeclPre (Decl *D) override {
4058- return !checkStatements;
4059- }
4060-
4061- void visitTypeRepr (TypeRepr *T) {
4062- // Do nothing for all TypeReprs except the ones listed below.
4063- }
4064-
4065- void visitIdentTypeRepr (IdentTypeRepr *T) {
4066- return ;
4067- }
4068-
4069- void visitRequirements (ArrayRef<RequirementRepr> reqts) {
4070- for (auto reqt : reqts) {
4071- if (reqt.getKind () == RequirementReprKind::SameType) {
4072- if (auto *repr = reqt.getFirstTypeRepr ())
4073- repr->walk (*this );
4074- if (auto *repr = reqt.getSecondTypeRepr ())
4075- repr->walk (*this );
4076- }
4077- }
4078- }
4079- };
4080-
4081- } // end anonymous namespace
4082-
4083- void TypeChecker::checkUnsupportedProtocolType (Decl *decl) {
4084- if (!decl || decl->isInvalid ())
4085- return ;
4086-
4087- auto &ctx = decl->getASTContext ();
4088- if (auto *protocolDecl = dyn_cast<ProtocolDecl>(decl)) {
4089- checkUnsupportedProtocolType (ctx, protocolDecl->getTrailingWhereClause ());
4090- } else if (auto *genericDecl = dyn_cast<GenericTypeDecl>(decl)) {
4091- checkUnsupportedProtocolType (ctx, genericDecl->getGenericParams ());
4092- checkUnsupportedProtocolType (ctx, genericDecl->getTrailingWhereClause ());
4093- } else if (auto *assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
4094- checkUnsupportedProtocolType (ctx, assocType->getTrailingWhereClause ());
4095- } else if (auto *extDecl = dyn_cast<ExtensionDecl>(decl)) {
4096- checkUnsupportedProtocolType (ctx, extDecl->getTrailingWhereClause ());
4097- } else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
4098- checkUnsupportedProtocolType (ctx, subscriptDecl->getGenericParams ());
4099- checkUnsupportedProtocolType (ctx, subscriptDecl->getTrailingWhereClause ());
4100- } else if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
4101- if (!isa<AccessorDecl>(funcDecl)) {
4102- checkUnsupportedProtocolType (ctx, funcDecl->getGenericParams ());
4103- checkUnsupportedProtocolType (ctx, funcDecl->getTrailingWhereClause ());
4104- }
4105- }
4106-
4107- if (isa<TypeDecl>(decl) || isa<ExtensionDecl>(decl))
4108- return ;
4109-
4110- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4111- decl->walk (visitor);
4112- }
4113-
4114- void TypeChecker::checkUnsupportedProtocolType (ASTContext &ctx, Stmt *stmt) {
4115- if (!stmt)
4116- return ;
4117-
4118- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ true );
4119- stmt->walk (visitor);
4120- }
4121-
4122- void TypeChecker::checkUnsupportedProtocolType (
4123- ASTContext &ctx, TrailingWhereClause *whereClause) {
4124- if (whereClause == nullptr )
4125- return ;
4126-
4127- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4128- visitor.visitRequirements (whereClause->getRequirements ());
4129- }
4130-
4131- void TypeChecker::checkUnsupportedProtocolType (
4132- ASTContext &ctx, GenericParamList *genericParams) {
4133- if (genericParams == nullptr )
4134- return ;
4135-
4136- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4137- visitor.visitRequirements (genericParams->getRequirements ());
4138- }
4139-
41404018Type CustomAttrTypeRequest::evaluate (Evaluator &eval, CustomAttr *attr,
41414019 DeclContext *dc,
41424020 CustomAttrTypeKind typeKind) const {
0 commit comments