@@ -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))
@@ -3921,18 +3926,33 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
39213926 }
39223927
39233928 // FIXME: Support compositions involving parameterized protocol types,
3924- // like Collection<String> & Sendable, etc.
3925- if (ty->isConstraintType () &&
3926- !ty->is <ParameterizedProtocolType>()) {
3927- auto layout = ty->getExistentialLayout ();
3928- if (auto superclass = layout.explicitSuperclass )
3929- if (checkSuperclass (tyR->getStartLoc (), superclass))
3930- continue ;
3931- if (!layout.getProtocols ().empty ())
3929+ // like 'any Collection<String> & Sendable', etc.
3930+ if (ty->isConstraintType ()) {
3931+ if (ty->is <ProtocolType>()) {
39323932 HasProtocol = true ;
3933+ Members.push_back (ty);
3934+ continue ;
3935+ }
39333936
3934- Members.push_back (ty);
3935- continue ;
3937+ if (ty->is <ParameterizedProtocolType>() &&
3938+ options.isParameterizedProtocolSupported () &&
3939+ options.getContext () != TypeResolverContext::ExistentialConstraint) {
3940+ HasProtocol = true ;
3941+ Members.push_back (ty);
3942+ continue ;
3943+ }
3944+
3945+ if (ty->is <ProtocolCompositionType>()) {
3946+ auto layout = ty->getExistentialLayout ();
3947+ if (auto superclass = layout.explicitSuperclass )
3948+ if (checkSuperclass (tyR->getStartLoc (), superclass))
3949+ continue ;
3950+ if (!layout.getProtocols ().empty ())
3951+ HasProtocol = true ;
3952+
3953+ Members.push_back (ty);
3954+ continue ;
3955+ }
39363956 }
39373957
39383958 diagnose (tyR->getStartLoc (),
0 commit comments