@@ -624,6 +624,38 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
624
624
auto &ctx = dc->getASTContext ();
625
625
auto &diags = ctx.Diags ;
626
626
627
+ if (ctx.LangOpts .EnableParametrizedProtocolTypes ) {
628
+ // Build ParametrizedProtocolType if the protocol has a primary associated
629
+ // type.
630
+ if (auto *protoType = type->getAs <ProtocolType>()) {
631
+ auto *protoDecl = protoType->getDecl ();
632
+ if (protoDecl->getPrimaryAssociatedType () == nullptr ) {
633
+ diags.diagnose (loc, diag::protocol_does_not_have_primary_assoc_type,
634
+ protoType);
635
+
636
+ return ErrorType::get (ctx);
637
+ }
638
+
639
+ auto genericArgs = generic->getGenericArgs ();
640
+
641
+ if (genericArgs.size () != 1 ) {
642
+ diags.diagnose (loc, diag::protocol_cannot_have_multiple_generic_arguments,
643
+ protoType);
644
+
645
+ return ErrorType::get (ctx);
646
+ }
647
+
648
+ auto genericResolution =
649
+ resolution.withOptions (adjustOptionsForGenericArgs (options));
650
+
651
+ Type argTy = genericResolution.resolveType (genericArgs[0 ], silParams);
652
+ if (!argTy || argTy->hasError ())
653
+ return ErrorType::get (ctx);
654
+
655
+ return ParametrizedProtocolType::get (ctx, protoType, argTy);
656
+ }
657
+ }
658
+
627
659
// We must either have an unbound generic type, or a generic type alias.
628
660
if (!type->is <UnboundGenericType>()) {
629
661
if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
0 commit comments