Skip to content

Commit 1ad7c91

Browse files
committed
Sema: Clean up some diagnostic logic in applyGenericArguments()
1 parent 575a29c commit 1ad7c91

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -816,37 +816,6 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
816816
return ErrorType::get(ctx);
817817
}
818818

819-
// Build ParameterizedProtocolType if the protocol has a primary associated
820-
// type and we're in a supported context.
821-
if (resolution.getOptions().isConstraintImplicitExistential() &&
822-
!ctx.LangOpts.hasFeature(Feature::ImplicitSome)) {
823-
824-
if (!genericArgs.empty()) {
825-
826-
SmallVector<Type, 2> argTys;
827-
for (auto *genericArg : genericArgs) {
828-
Type argTy = resolution.resolveType(genericArg);
829-
if (!argTy || argTy->hasError())
830-
return ErrorType::get(ctx);
831-
832-
argTys.push_back(argTy);
833-
}
834-
835-
auto parameterized =
836-
ParameterizedProtocolType::get(ctx, protoType, argTys);
837-
diags.diagnose(loc, diag::existential_requires_any, parameterized,
838-
ExistentialType::get(parameterized),
839-
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
840-
} else {
841-
diags.diagnose(loc, diag::existential_requires_any,
842-
protoDecl->getDeclaredInterfaceType(),
843-
protoDecl->getDeclaredExistentialType(),
844-
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
845-
}
846-
847-
return ErrorType::get(ctx);
848-
}
849-
850819
// Disallow opaque types anywhere in the structure of the generic arguments
851820
// to a parameterized existential type.
852821
if (options.is(TypeResolverContext::ExistentialConstraint))
@@ -855,6 +824,7 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
855824
TypeResolverContext::ProtocolGenericArgument);
856825
auto genericResolution = resolution.withOptions(argOptions);
857826

827+
// Resolve the generic arguments.
858828
SmallVector<Type, 2> argTys;
859829
for (auto *genericArg : genericArgs) {
860830
Type argTy = genericResolution.resolveType(genericArg, silContext);
@@ -864,7 +834,20 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
864834
argTys.push_back(argTy);
865835
}
866836

867-
return ParameterizedProtocolType::get(ctx, protoType, argTys);
837+
auto parameterized =
838+
ParameterizedProtocolType::get(ctx, protoType, argTys);
839+
840+
// Build ParameterizedProtocolType if the protocol has primary associated
841+
// types and we're in a supported context.
842+
if (resolution.getOptions().isConstraintImplicitExistential() &&
843+
!ctx.LangOpts.hasFeature(Feature::ImplicitSome)) {
844+
diags.diagnose(loc, diag::existential_requires_any, parameterized,
845+
ExistentialType::get(parameterized),
846+
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
847+
return ErrorType::get(ctx);
848+
}
849+
850+
return parameterized;
868851
}
869852

870853
// We must either have an unbound generic type, or a generic type alias.

0 commit comments

Comments
 (0)