@@ -770,37 +770,6 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
770770 return ErrorType::get (ctx);
771771 }
772772
773- // Build ParameterizedProtocolType if the protocol has a primary associated
774- // type and we're in a supported context.
775- if (resolution.getOptions ().isConstraintImplicitExistential () &&
776- !ctx.LangOpts .hasFeature (Feature::ImplicitSome)) {
777-
778- if (!genericArgs.empty ()) {
779-
780- SmallVector<Type, 2 > argTys;
781- for (auto *genericArg : genericArgs) {
782- Type argTy = resolution.resolveType (genericArg);
783- if (!argTy || argTy->hasError ())
784- return ErrorType::get (ctx);
785-
786- argTys.push_back (argTy);
787- }
788-
789- auto parameterized =
790- ParameterizedProtocolType::get (ctx, protoType, argTys);
791- diags.diagnose (loc, diag::existential_requires_any, parameterized,
792- ExistentialType::get (parameterized),
793- /* isAlias=*/ isa<TypeAliasType>(type.getPointer ()));
794- } else {
795- diags.diagnose (loc, diag::existential_requires_any,
796- protoDecl->getDeclaredInterfaceType (),
797- protoDecl->getDeclaredExistentialType (),
798- /* isAlias=*/ isa<TypeAliasType>(type.getPointer ()));
799- }
800-
801- return ErrorType::get (ctx);
802- }
803-
804773 // Disallow opaque types anywhere in the structure of the generic arguments
805774 // to a parameterized existential type.
806775 if (options.is (TypeResolverContext::ExistentialConstraint))
@@ -809,6 +778,7 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
809778 TypeResolverContext::ProtocolGenericArgument);
810779 auto genericResolution = resolution.withOptions (argOptions);
811780
781+ // Resolve the generic arguments.
812782 SmallVector<Type, 2 > argTys;
813783 for (auto *genericArg : genericArgs) {
814784 Type argTy = genericResolution.resolveType (genericArg, silContext);
@@ -818,7 +788,20 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
818788 argTys.push_back (argTy);
819789 }
820790
821- return ParameterizedProtocolType::get (ctx, protoType, argTys);
791+ auto parameterized =
792+ ParameterizedProtocolType::get (ctx, protoType, argTys);
793+
794+ // Build ParameterizedProtocolType if the protocol has primary associated
795+ // types and we're in a supported context.
796+ if (resolution.getOptions ().isConstraintImplicitExistential () &&
797+ !ctx.LangOpts .hasFeature (Feature::ImplicitSome)) {
798+ diags.diagnose (loc, diag::existential_requires_any, parameterized,
799+ ExistentialType::get (parameterized),
800+ /* isAlias=*/ isa<TypeAliasType>(type.getPointer ()));
801+ return ErrorType::get (ctx);
802+ }
803+
804+ return parameterized;
822805 }
823806
824807 // We must either have an unbound generic type, or a generic type alias.
0 commit comments