@@ -654,20 +654,35 @@ void swift::rewriting::realizeInheritedRequirements(
654654 }
655655}
656656
657+ static bool shouldSuggestConcreteTypeFixit (
658+ Type type, AllowConcreteTypePolicy concreteTypePolicy) {
659+ switch (concreteTypePolicy) {
660+ case AllowConcreteTypePolicy::All:
661+ return true ;
662+
663+ case AllowConcreteTypePolicy::AssocTypes:
664+ return type->is <DependentMemberType>();
665+
666+ case AllowConcreteTypePolicy::NestedAssocTypes:
667+ if (auto *memberType = type->getAs <DependentMemberType>())
668+ return memberType->getBase ()->is <DependentMemberType>();
669+
670+ return false ;
671+ }
672+ }
673+
657674// / Emit diagnostics for the given \c RequirementErrors.
658675// /
659676// / \param ctx The AST context in which to emit diagnostics.
660677// / \param errors The set of requirement diagnostics to be emitted.
661- // / \param allowConcreteGenericParams Whether concrete type parameters
662- // / are permitted in the generic signature. If true, diagnostics will
663- // / offer fix-its to turn invalid type requirements, e.g. T: Int, into
664- // / same-type requirements.
678+ // / \param concreteTypePolicy Whether fix-its should be offered to turn
679+ // / invalid type requirements, e.g. T: Int, into same-type requirements.
665680// /
666681// / \returns true if any errors were emitted, and false otherwise (including
667682// / when only warnings were emitted).
668683bool swift::rewriting::diagnoseRequirementErrors (
669684 ASTContext &ctx, ArrayRef<RequirementError> errors,
670- bool allowConcreteGenericParams ) {
685+ AllowConcreteTypePolicy concreteTypePolicy ) {
671686 bool diagnosedError = false ;
672687
673688 for (auto error : errors) {
@@ -697,7 +712,7 @@ bool swift::rewriting::diagnoseRequirementErrors(
697712 return subjectTypeName;
698713 };
699714
700- if (allowConcreteGenericParams ) {
715+ if (shouldSuggestConcreteTypeFixit (subjectType, concreteTypePolicy) ) {
701716 auto options = PrintOptions::forDiagnosticArguments ();
702717 auto subjectTypeName = subjectType.getString (options);
703718 auto subjectTypeNameWithoutSelf = getNameWithoutSelf (subjectTypeName);
@@ -902,7 +917,8 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
902917
903918 if (ctx.LangOpts .RequirementMachineProtocolSignatures ==
904919 RequirementMachineMode::Enabled) {
905- diagnoseRequirementErrors (ctx, errors, /* allowConcreteGenericParams=*/ false );
920+ diagnoseRequirementErrors (ctx, errors,
921+ AllowConcreteTypePolicy::NestedAssocTypes);
906922 }
907923
908924 return ctx.AllocateCopy (result);
@@ -1175,7 +1191,8 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
11751191
11761192 if (ctx.LangOpts .RequirementMachineProtocolSignatures ==
11771193 RequirementMachineMode::Enabled) {
1178- diagnoseRequirementErrors (ctx, errors, /* allowConcreteGenericParams=*/ false );
1194+ diagnoseRequirementErrors (ctx, errors,
1195+ AllowConcreteTypePolicy::NestedAssocTypes);
11791196 }
11801197
11811198 return ctx.AllocateCopy (result);
0 commit comments