@@ -543,10 +543,6 @@ bool TypeChecker::checkContextualRequirements(GenericTypeDecl *decl,
543
543
noteLoc = loc;
544
544
}
545
545
546
- if (contextSig) {
547
- parentTy = contextSig.getGenericEnvironment ()->mapTypeIntoContext (parentTy);
548
- }
549
-
550
546
const auto subMap = parentTy->getContextSubstitutions (decl->getDeclContext ());
551
547
const auto genericSig = decl->getGenericSignature ();
552
548
@@ -556,7 +552,16 @@ bool TypeChecker::checkContextualRequirements(GenericTypeDecl *decl,
556
552
decl->getDeclaredInterfaceType (),
557
553
genericSig.getGenericParams (),
558
554
genericSig.getRequirements (),
559
- QueryTypeSubstitutionMap{subMap});
555
+ [&](SubstitutableType *type) -> Type {
556
+ auto result = QueryTypeSubstitutionMap{subMap}(type);
557
+ if (result->hasTypeParameter ()) {
558
+ if (contextSig) {
559
+ auto *genericEnv = contextSig.getGenericEnvironment ();
560
+ return genericEnv->mapTypeIntoContext (result);
561
+ }
562
+ }
563
+ return result;
564
+ });
560
565
561
566
switch (result) {
562
567
case RequirementCheckResult::Failure:
@@ -845,15 +850,6 @@ Type TypeResolution::applyUnboundGenericArguments(
845
850
// Check the generic arguments against the requirements of the declaration's
846
851
// generic signature.
847
852
848
- // First, map substitutions into context.
849
- TypeSubstitutionMap contextualSubs = subs;
850
- if (const auto contextSig = getGenericSignature ()) {
851
- auto *genericEnv = contextSig.getGenericEnvironment ();
852
- for (auto &pair : contextualSubs) {
853
- pair.second = genericEnv->mapTypeIntoContext (pair.second );
854
- }
855
- }
856
-
857
853
SourceLoc noteLoc = decl->getLoc ();
858
854
if (noteLoc.isInvalid ())
859
855
noteLoc = loc;
@@ -862,7 +858,16 @@ Type TypeResolution::applyUnboundGenericArguments(
862
858
module , loc, noteLoc,
863
859
UnboundGenericType::get (decl, parentTy, getASTContext ()),
864
860
genericSig.getGenericParams (), genericSig.getRequirements (),
865
- QueryTypeSubstitutionMap{contextualSubs});
861
+ [&](SubstitutableType *type) -> Type {
862
+ auto result = QueryTypeSubstitutionMap{subs}(type);
863
+ if (result->hasTypeParameter ()) {
864
+ if (const auto contextSig = getGenericSignature ()) {
865
+ auto *genericEnv = contextSig.getGenericEnvironment ();
866
+ return genericEnv->mapTypeIntoContext (result);
867
+ }
868
+ }
869
+ return result;
870
+ });
866
871
867
872
switch (result) {
868
873
case RequirementCheckResult::Failure:
0 commit comments