@@ -2236,57 +2236,47 @@ TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc,
22362236 assert (ParentNameLoc.isValid ());
22372237 assert (NameLoc.isValid ());
22382238
2239- // The base component is the parent type.
2240- auto *ParentComp = new (C) SimpleIdentTypeRepr (ParentNameLoc,
2241- Parent->createNameRef ());
2242- ParentComp ->setValue (Parent, nullptr );
2239+ // The base is the parent type.
2240+ auto *BaseTR =
2241+ new (C) SimpleIdentTypeRepr (ParentNameLoc, Parent->createNameRef ());
2242+ BaseTR ->setValue (Parent, nullptr );
22432243
2244- // The member component is the member we just found.
2245- auto *MemberComp =
2246- new (C) SimpleIdentTypeRepr (NameLoc, Decl->createNameRef ());
2247- MemberComp->setValue (Decl, nullptr );
2244+ auto *MemberTR =
2245+ MemberTypeRepr::create (C, BaseTR, NameLoc, Decl->createNameRef ());
2246+ MemberTR->setValue (Decl, nullptr );
22482247
2249- auto *TR = MemberTypeRepr::create (C, ParentComp, {MemberComp});
2250- return new (C) TypeExpr (TR);
2248+ return new (C) TypeExpr (MemberTR);
22512249}
22522250
22532251TypeExpr *TypeExpr::createForMemberDecl (TypeRepr *ParentTR, DeclNameLoc NameLoc,
22542252 TypeDecl *Decl) {
22552253 ASTContext &C = Decl->getASTContext ();
22562254
2257- // Add a new component for the member we just found.
2258- auto *NewComp = new (C) SimpleIdentTypeRepr ( NameLoc, Decl->createNameRef ());
2259- NewComp ->setValue (Decl, nullptr );
2255+ auto *MemberTR =
2256+ MemberTypeRepr::create (C, ParentTR, NameLoc, Decl->createNameRef ());
2257+ MemberTR ->setValue (Decl, nullptr );
22602258
2261- TypeRepr *TR = nullptr ;
2262- if (auto *DeclRefTR = dyn_cast<DeclRefTypeRepr>(ParentTR)) {
2263- // Create a new list of components.
2264- SmallVector<IdentTypeRepr *, 4 > Components;
2265- if (auto *MemberTR = dyn_cast<MemberTypeRepr>(ParentTR)) {
2266- auto MemberComps = MemberTR->getMemberComponents ();
2267- Components.append (MemberComps.begin (), MemberComps.end ());
2268- }
2269-
2270- Components.push_back (NewComp);
2271- TR = MemberTypeRepr::create (C, DeclRefTR->getRoot (), Components);
2272- } else {
2273- TR = MemberTypeRepr::create (C, ParentTR, NewComp);
2274- }
2275-
2276- return new (C) TypeExpr (TR);
2259+ return new (C) TypeExpr (MemberTR);
22772260}
22782261
22792262TypeExpr *TypeExpr::createForSpecializedDecl (DeclRefTypeRepr *ParentTR,
22802263 ArrayRef<TypeRepr *> Args,
22812264 SourceRange AngleLocs,
22822265 ASTContext &C) {
2283- auto *lastComp = ParentTR-> getLastComponent () ;
2266+ DeclRefTypeRepr *specializedTR = nullptr ;
22842267
2285- if (!isa<SimpleIdentTypeRepr>(lastComp) || !lastComp->getBoundDecl ())
2268+ auto *boundDecl = ParentTR->getBoundDecl ();
2269+ if (!boundDecl || ParentTR->hasGenericArgList ()) {
22862270 return nullptr ;
2271+ }
22872272
2288- if (isa<TypeAliasDecl>(lastComp->getBoundDecl ())) {
2289- if (auto *memberTR = dyn_cast<MemberTypeRepr>(ParentTR)) {
2273+ if (isa<IdentTypeRepr>(ParentTR)) {
2274+ specializedTR = GenericIdentTypeRepr::create (
2275+ C, ParentTR->getNameLoc (), ParentTR->getNameRef (), Args, AngleLocs);
2276+ specializedTR->setValue (boundDecl, ParentTR->getDeclContext ());
2277+ } else {
2278+ auto *const memberTR = cast<MemberTypeRepr>(ParentTR);
2279+ if (isa<TypeAliasDecl>(boundDecl)) {
22902280 // If any of our parent types are unbound, bail out and let
22912281 // the constraint solver can infer generic parameters for them.
22922282 //
@@ -2299,48 +2289,30 @@ TypeExpr *TypeExpr::createForSpecializedDecl(DeclRefTypeRepr *ParentTR,
22992289 //
23002290 // FIXME: Once we can model generic typealiases properly, rip
23012291 // this out.
2302- auto isUnboundGenericComponent = [](IdentTypeRepr *ITR) -> bool {
2303- if (isa<SimpleIdentTypeRepr>(ITR)) {
2304- auto *decl = dyn_cast_or_null<GenericTypeDecl>(ITR->getBoundDecl ());
2292+ MemberTypeRepr *currTR = memberTR;
2293+ while (auto *declRefBaseTR =
2294+ dyn_cast<DeclRefTypeRepr>(currTR->getBase ())) {
2295+ if (!declRefBaseTR->hasGenericArgList ()) {
2296+ auto *decl =
2297+ dyn_cast_or_null<GenericTypeDecl>(declRefBaseTR->getBoundDecl ());
23052298 if (decl && decl->isGeneric ())
2306- return true ;
2299+ return nullptr ;
23072300 }
23082301
2309- return false ;
2310- };
2311-
2312- for (auto *comp : memberTR->getMemberComponents ().drop_back ()) {
2313- if (isUnboundGenericComponent (comp))
2314- return nullptr ;
2315- }
2316-
2317- if (auto *identRoot = dyn_cast<IdentTypeRepr>(memberTR->getRoot ())) {
2318- if (isUnboundGenericComponent (identRoot))
2319- return nullptr ;
2302+ currTR = dyn_cast<MemberTypeRepr>(declRefBaseTR);
2303+ if (!currTR) {
2304+ break ;
2305+ }
23202306 }
23212307 }
2322- }
23232308
2324- auto *genericComp = GenericIdentTypeRepr::create (
2325- C, lastComp->getNameLoc (), lastComp->getNameRef (), Args, AngleLocs);
2326- genericComp->setValue (lastComp->getBoundDecl (), lastComp->getDeclContext ());
2327-
2328- TypeRepr *TR = nullptr ;
2329- if (auto *memberTR = dyn_cast<MemberTypeRepr>(ParentTR)) {
2330- auto oldMemberComps = memberTR->getMemberComponents ().drop_back ();
2331-
2332- // Create a new list of member components, replacing the last one with the
2333- // new specialized one.
2334- SmallVector<IdentTypeRepr *, 2 > newMemberComps;
2335- newMemberComps.append (oldMemberComps.begin (), oldMemberComps.end ());
2336- newMemberComps.push_back (genericComp);
2337-
2338- TR = MemberTypeRepr::create (C, memberTR->getRoot (), newMemberComps);
2339- } else {
2340- TR = genericComp;
2309+ specializedTR =
2310+ MemberTypeRepr::create (C, memberTR->getBase (), ParentTR->getNameLoc (),
2311+ ParentTR->getNameRef (), Args, AngleLocs);
2312+ specializedTR->setValue (boundDecl, ParentTR->getDeclContext ());
23412313 }
23422314
2343- return new (C) TypeExpr (TR );
2315+ return new (C) TypeExpr (specializedTR );
23442316}
23452317
23462318// Create an implicit TypeExpr, with location information even though it
0 commit comments