@@ -629,15 +629,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
629629 auto &diags = ctx.Diags ;
630630
631631 if (auto *protoType = type->getAs <ProtocolType>()) {
632- // Build ParameterizedProtocolType if the protocol has a primary associated
633- // type and we're in a supported context (for now just generic requirements,
634- // inheritance clause, extension binding).
635- if (!resolution.getOptions ().isParameterizedProtocolSupported ()) {
636- diags.diagnose (loc, diag::parameterized_protocol_not_supported);
637- return ErrorType::get (ctx);
638- }
639-
640632 auto *protoDecl = protoType->getDecl ();
633+
641634 auto assocTypes = protoDecl->getPrimaryAssociatedTypes ();
642635 if (assocTypes.empty ()) {
643636 diags.diagnose (loc, diag::protocol_does_not_have_primary_assoc_type,
@@ -657,6 +650,18 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
657650 return ErrorType::get (ctx);
658651 }
659652
653+ // Build ParameterizedProtocolType if the protocol has a primary associated
654+ // type and we're in a supported context (for now just generic requirements,
655+ // inheritance clause, extension binding).
656+ if (!resolution.getOptions ().isParameterizedProtocolSupported ()) {
657+ diags.diagnose (loc, diag::existential_requires_any,
658+ protoDecl->getDeclaredInterfaceType (),
659+ protoDecl->getExistentialType (),
660+ /* isAlias=*/ isa<TypeAliasType>(type.getPointer ()));
661+
662+ return ErrorType::get (ctx);
663+ }
664+
660665 // Disallow opaque types anywhere in the structure of the generic arguments
661666 // to a parameterized existential type.
662667 if (options.is (TypeResolverContext::ExistentialConstraint))
@@ -3932,18 +3937,33 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
39323937 }
39333938
39343939 // FIXME: Support compositions involving parameterized protocol types,
3935- // like Collection<String> & Sendable, etc.
3936- if (ty->isConstraintType () &&
3937- !ty->is <ParameterizedProtocolType>()) {
3938- auto layout = ty->getExistentialLayout ();
3939- if (auto superclass = layout.explicitSuperclass )
3940- if (checkSuperclass (tyR->getStartLoc (), superclass))
3941- continue ;
3942- if (!layout.getProtocols ().empty ())
3940+ // like 'any Collection<String> & Sendable', etc.
3941+ if (ty->isConstraintType ()) {
3942+ if (ty->is <ProtocolType>()) {
39433943 HasProtocol = true ;
3944+ Members.push_back (ty);
3945+ continue ;
3946+ }
39443947
3945- Members.push_back (ty);
3946- continue ;
3948+ if (ty->is <ParameterizedProtocolType>() &&
3949+ options.isParameterizedProtocolSupported () &&
3950+ options.getContext () != TypeResolverContext::ExistentialConstraint) {
3951+ HasProtocol = true ;
3952+ Members.push_back (ty);
3953+ continue ;
3954+ }
3955+
3956+ if (ty->is <ProtocolCompositionType>()) {
3957+ auto layout = ty->getExistentialLayout ();
3958+ if (auto superclass = layout.explicitSuperclass )
3959+ if (checkSuperclass (tyR->getStartLoc (), superclass))
3960+ continue ;
3961+ if (!layout.getProtocols ().empty ())
3962+ HasProtocol = true ;
3963+
3964+ Members.push_back (ty);
3965+ continue ;
3966+ }
39473967 }
39483968
39493969 diagnose (tyR->getStartLoc (),
0 commit comments