@@ -654,20 +654,35 @@ void swift::rewriting::realizeInheritedRequirements(
654
654
}
655
655
}
656
656
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
+
657
674
// / Emit diagnostics for the given \c RequirementErrors.
658
675
// /
659
676
// / \param ctx The AST context in which to emit diagnostics.
660
677
// / \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.
665
680
// /
666
681
// / \returns true if any errors were emitted, and false otherwise (including
667
682
// / when only warnings were emitted).
668
683
bool swift::rewriting::diagnoseRequirementErrors (
669
684
ASTContext &ctx, ArrayRef<RequirementError> errors,
670
- bool allowConcreteGenericParams ) {
685
+ AllowConcreteTypePolicy concreteTypePolicy ) {
671
686
bool diagnosedError = false ;
672
687
673
688
for (auto error : errors) {
@@ -697,7 +712,7 @@ bool swift::rewriting::diagnoseRequirementErrors(
697
712
return subjectTypeName;
698
713
};
699
714
700
- if (allowConcreteGenericParams ) {
715
+ if (shouldSuggestConcreteTypeFixit (subjectType, concreteTypePolicy) ) {
701
716
auto options = PrintOptions::forDiagnosticArguments ();
702
717
auto subjectTypeName = subjectType.getString (options);
703
718
auto subjectTypeNameWithoutSelf = getNameWithoutSelf (subjectTypeName);
@@ -902,7 +917,8 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
902
917
903
918
if (ctx.LangOpts .RequirementMachineProtocolSignatures ==
904
919
RequirementMachineMode::Enabled) {
905
- diagnoseRequirementErrors (ctx, errors, /* allowConcreteGenericParams=*/ false );
920
+ diagnoseRequirementErrors (ctx, errors,
921
+ AllowConcreteTypePolicy::NestedAssocTypes);
906
922
}
907
923
908
924
return ctx.AllocateCopy (result);
@@ -1175,7 +1191,8 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
1175
1191
1176
1192
if (ctx.LangOpts .RequirementMachineProtocolSignatures ==
1177
1193
RequirementMachineMode::Enabled) {
1178
- diagnoseRequirementErrors (ctx, errors, /* allowConcreteGenericParams=*/ false );
1194
+ diagnoseRequirementErrors (ctx, errors,
1195
+ AllowConcreteTypePolicy::NestedAssocTypes);
1179
1196
}
1180
1197
1181
1198
return ctx.AllocateCopy (result);
0 commit comments