@@ -817,6 +817,71 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
817817// / Checking bound generic type arguments
818818// /
819819
820+ void TypeChecker::diagnoseRequirementFailure (
821+ const CheckGenericArgumentsResult::RequirementFailureInfo &reqFailureInfo,
822+ SourceLoc errorLoc, SourceLoc noteLoc, Type targetTy,
823+ TypeArrayView<GenericTypeParamType> genericParams,
824+ TypeSubstitutionFn substitutions, ModuleDecl *module ) {
825+ assert (errorLoc.isValid () && noteLoc.isValid ());
826+
827+ const auto &req = reqFailureInfo.Req ;
828+ const auto &substReq = reqFailureInfo.SubstReq ;
829+
830+ Diag<Type, Type, Type> diagnostic;
831+ Diag<Type, Type, StringRef> diagnosticNote;
832+
833+ const auto reqKind = req.getKind ();
834+ switch (reqKind) {
835+ case RequirementKind::Conformance: {
836+ diagnoseConformanceFailure (substReq.getFirstType (),
837+ substReq.getProtocolDecl (), module , errorLoc);
838+
839+ if (reqFailureInfo.ReqPath .empty ())
840+ return ;
841+
842+ diagnostic = diag::type_does_not_conform_owner;
843+ diagnosticNote = diag::type_does_not_inherit_or_conform_requirement;
844+ break ;
845+ }
846+
847+ case RequirementKind::Layout:
848+ diagnostic = diag::type_is_not_a_class;
849+ diagnosticNote = diag::anyobject_requirement;
850+ break ;
851+
852+ case RequirementKind::Superclass:
853+ diagnostic = diag::type_does_not_inherit;
854+ diagnosticNote = diag::type_does_not_inherit_or_conform_requirement;
855+ break ;
856+
857+ case RequirementKind::SameType:
858+ diagnostic = diag::types_not_equal;
859+ diagnosticNote = diag::types_not_equal_requirement;
860+ break ;
861+ }
862+
863+ Type secondTy, substSecondTy;
864+ if (req.getKind () != RequirementKind::Layout) {
865+ secondTy = req.getSecondType ();
866+ substSecondTy = substReq.getSecondType ();
867+ }
868+
869+ ASTContext &ctx = module ->getASTContext ();
870+ // FIXME: Poor source-location information.
871+ ctx.Diags .diagnose (errorLoc, diagnostic, targetTy, substReq.getFirstType (),
872+ substSecondTy);
873+
874+ const auto genericParamBindingsText =
875+ TypeChecker::gatherGenericParamBindingsText (
876+ {req.getFirstType (), secondTy}, genericParams, substitutions);
877+
878+ ctx.Diags .diagnose (noteLoc, diagnosticNote, req.getFirstType (), secondTy,
879+ genericParamBindingsText);
880+
881+ ParentConditionalConformance::diagnoseConformanceStack (
882+ ctx.Diags , noteLoc, reqFailureInfo.ReqPath );
883+ }
884+
820885RequirementCheckResult TypeChecker::checkGenericArguments (
821886 ModuleDecl *module , SourceLoc loc, SourceLoc noteLoc, Type owner,
822887 TypeArrayView<GenericTypeParamType> genericParams,
0 commit comments