@@ -305,29 +305,29 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
305
305
if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl))
306
306
return BoundGenericType::get (nominalDecl, parent, args);
307
307
308
- // Combine the substitutions from our parent type with our generic
309
- // arguments.
310
- TypeSubstitutionMap subs;
311
- if (parent)
312
- subs = parent->getContextSubstitutions (decl->getDeclContext ());
313
-
314
308
auto *aliasDecl = cast<TypeAliasDecl>(decl);
309
+ auto *dc = aliasDecl->getDeclContext ();
315
310
316
- auto genericSig = aliasDecl->getGenericSignature ();
317
- for (unsigned i = 0 , e = args.size (); i < e; ++i) {
318
- auto origTy = genericSig.getInnermostGenericParams ()[i];
319
- auto substTy = args[i];
311
+ SmallVector<Type, 2 > subs;
320
312
321
- subs[origTy->getCanonicalType ()->castTo <GenericTypeParamType>()] =
322
- substTy;
313
+ // Combine the substitutions from our parent type with our generic
314
+ // arguments.
315
+ if (dc->isLocalContext ()) {
316
+ for (auto *param : dc->getGenericSignatureOfContext ().getGenericParams ()) {
317
+ subs.push_back (param);
318
+ }
319
+ } else if (parent) {
320
+ auto parentSubs = parent->getContextSubstitutionMap (
321
+ dc).getReplacementTypes ();
322
+ subs.append (parentSubs.begin (), parentSubs.end ());
323
323
}
324
324
325
- auto subMap = SubstitutionMap::get (genericSig,
326
- QueryTypeSubstitutionMap{subs},
327
- LookUpConformanceInModule ());
328
- if (!subMap)
329
- return Type ();
325
+ auto genericSig = aliasDecl->getGenericSignature ();
326
+ ASSERT (genericSig.getInnermostGenericParams ().size () == args.size ());
327
+ subs.append (args.begin (), args.end ());
330
328
329
+ auto subMap = SubstitutionMap::get (genericSig, subs,
330
+ LookUpConformanceInModule ());
331
331
return aliasDecl->getDeclaredInterfaceType ().subst (subMap);
332
332
}
333
333
0 commit comments