Skip to content

Commit 6be15e2

Browse files
committed
[Sema] Improve explicit 'any' diagnostic for ParameterizedProtocolType
Diagnostic message should include ParameterizedProtocolType instead of the ProtocolType i.e. 'any P<T>' vs 'any P'
1 parent 800a966 commit 6be15e2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,32 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
758758
}
759759

760760
// Build ParameterizedProtocolType if the protocol has a primary associated
761-
// type and we're in a supported context (for now just generic requirements,
762-
// inheritance clause, extension binding).
761+
// type and we're in a supported context.
763762
if (resolution.getOptions().isConstraintImplicitExistential() &&
764763
!ctx.LangOpts.hasFeature(Feature::ImplicitSome)) {
765-
diags.diagnose(loc, diag::existential_requires_any,
766-
protoDecl->getDeclaredInterfaceType(),
767-
protoDecl->getDeclaredExistentialType(),
768-
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
764+
765+
if (!genericArgs.empty()) {
766+
767+
SmallVector<Type, 2> argTys;
768+
for (auto *genericArg : genericArgs) {
769+
Type argTy = resolution.resolveType(genericArg);
770+
if (!argTy || argTy->hasError())
771+
return ErrorType::get(ctx);
772+
773+
argTys.push_back(argTy);
774+
}
775+
776+
auto parameterized =
777+
ParameterizedProtocolType::get(ctx, protoType, argTys);
778+
diags.diagnose(loc, diag::existential_requires_any, parameterized,
779+
ExistentialType::get(parameterized),
780+
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
781+
} else {
782+
diags.diagnose(loc, diag::existential_requires_any,
783+
protoDecl->getDeclaredInterfaceType(),
784+
protoDecl->getDeclaredExistentialType(),
785+
/*isAlias=*/isa<TypeAliasType>(type.getPointer()));
786+
}
769787

770788
return ErrorType::get(ctx);
771789
}

0 commit comments

Comments
 (0)