@@ -3949,128 +3949,6 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
39493949 return resultType;
39503950}
39513951
3952- namespace {
3953-
3954- class UnsupportedProtocolVisitor
3955- : public TypeReprVisitor<UnsupportedProtocolVisitor>, public ASTWalker
3956- {
3957- ASTContext &Ctx;
3958- bool checkStatements;
3959- bool hitTopStmt;
3960-
3961- public:
3962- UnsupportedProtocolVisitor (ASTContext &ctx, bool checkStatements)
3963- : Ctx(ctx), checkStatements(checkStatements), hitTopStmt(false ) { }
3964-
3965- bool walkToTypeReprPre (TypeRepr *T) override {
3966- if (T->isInvalid ())
3967- return false ;
3968- if (auto compound = dyn_cast<CompoundIdentTypeRepr>(T)) {
3969- // Only visit the last component to check, because nested typealiases in
3970- // existentials are okay.
3971- visit (compound->getComponentRange ().back ());
3972- return false ;
3973- }
3974- // Arbitrary protocol constraints are OK on opaque types.
3975- if (isa<OpaqueReturnTypeRepr>(T))
3976- return false ;
3977-
3978- visit (T);
3979- return true ;
3980- }
3981-
3982- std::pair<bool , Stmt*> walkToStmtPre (Stmt *S) override {
3983- if (checkStatements && !hitTopStmt) {
3984- hitTopStmt = true ;
3985- return { true , S };
3986- }
3987-
3988- return { false , S };
3989- }
3990-
3991- bool walkToDeclPre (Decl *D) override {
3992- return !checkStatements;
3993- }
3994-
3995- void visitTypeRepr (TypeRepr *T) {
3996- // Do nothing for all TypeReprs except the ones listed below.
3997- }
3998-
3999- void visitIdentTypeRepr (IdentTypeRepr *T) {
4000- return ;
4001- }
4002-
4003- void visitRequirements (ArrayRef<RequirementRepr> reqts) {
4004- for (auto reqt : reqts) {
4005- if (reqt.getKind () == RequirementReprKind::SameType) {
4006- if (auto *repr = reqt.getFirstTypeRepr ())
4007- repr->walk (*this );
4008- if (auto *repr = reqt.getSecondTypeRepr ())
4009- repr->walk (*this );
4010- }
4011- }
4012- }
4013- };
4014-
4015- } // end anonymous namespace
4016-
4017- void TypeChecker::checkUnsupportedProtocolType (Decl *decl) {
4018- if (!decl || decl->isInvalid ())
4019- return ;
4020-
4021- auto &ctx = decl->getASTContext ();
4022- if (auto *protocolDecl = dyn_cast<ProtocolDecl>(decl)) {
4023- checkUnsupportedProtocolType (ctx, protocolDecl->getTrailingWhereClause ());
4024- } else if (auto *genericDecl = dyn_cast<GenericTypeDecl>(decl)) {
4025- checkUnsupportedProtocolType (ctx, genericDecl->getGenericParams ());
4026- checkUnsupportedProtocolType (ctx, genericDecl->getTrailingWhereClause ());
4027- } else if (auto *assocType = dyn_cast<AssociatedTypeDecl>(decl)) {
4028- checkUnsupportedProtocolType (ctx, assocType->getTrailingWhereClause ());
4029- } else if (auto *extDecl = dyn_cast<ExtensionDecl>(decl)) {
4030- checkUnsupportedProtocolType (ctx, extDecl->getTrailingWhereClause ());
4031- } else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
4032- checkUnsupportedProtocolType (ctx, subscriptDecl->getGenericParams ());
4033- checkUnsupportedProtocolType (ctx, subscriptDecl->getTrailingWhereClause ());
4034- } else if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
4035- if (!isa<AccessorDecl>(funcDecl)) {
4036- checkUnsupportedProtocolType (ctx, funcDecl->getGenericParams ());
4037- checkUnsupportedProtocolType (ctx, funcDecl->getTrailingWhereClause ());
4038- }
4039- }
4040-
4041- if (isa<TypeDecl>(decl) || isa<ExtensionDecl>(decl))
4042- return ;
4043-
4044- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4045- decl->walk (visitor);
4046- }
4047-
4048- void TypeChecker::checkUnsupportedProtocolType (ASTContext &ctx, Stmt *stmt) {
4049- if (!stmt)
4050- return ;
4051-
4052- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ true );
4053- stmt->walk (visitor);
4054- }
4055-
4056- void TypeChecker::checkUnsupportedProtocolType (
4057- ASTContext &ctx, TrailingWhereClause *whereClause) {
4058- if (whereClause == nullptr )
4059- return ;
4060-
4061- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4062- visitor.visitRequirements (whereClause->getRequirements ());
4063- }
4064-
4065- void TypeChecker::checkUnsupportedProtocolType (
4066- ASTContext &ctx, GenericParamList *genericParams) {
4067- if (genericParams == nullptr )
4068- return ;
4069-
4070- UnsupportedProtocolVisitor visitor (ctx, /* checkStatements=*/ false );
4071- visitor.visitRequirements (genericParams->getRequirements ());
4072- }
4073-
40743952Type CustomAttrTypeRequest::evaluate (Evaluator &eval, CustomAttr *attr,
40753953 DeclContext *dc,
40763954 CustomAttrTypeKind typeKind) const {
0 commit comments