@@ -3836,8 +3836,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
3836
3836
ConstraintKind kind,
3837
3837
ConstraintLocatorBuilder locator,
3838
3838
TypeMatchOptions flags) {
3839
+ auto *typeVar = type->getAs <TypeVariableType>();
3839
3840
if (shouldAttemptFixes ()) {
3840
- auto *typeVar = type->getAs <TypeVariableType>();
3841
3841
// If type variable, associated with this conformance check,
3842
3842
// has been determined to be a "hole" in constraint system,
3843
3843
// let's consider this check a success without recording
@@ -3987,6 +3987,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
3987
3987
return SolutionKind::Error;
3988
3988
3989
3989
if (path.back ().is <LocatorPathElt::AnyRequirement>()) {
3990
+ // If this is a requirement associated with `Self` which is bound
3991
+ // to `Any`, let's consider this "too incorrect" to continue.
3992
+ //
3993
+ // This helps us to filter out cases like operator overloads where
3994
+ // `Self` type comes from e.g. default for collection element -
3995
+ // `[1, "hello"].map { $0 + 1 }`. Main problem here is that
3996
+ // collection type couldn't be determined without unification to
3997
+ // `Any` and `+` failing for all numeric overloads is just a consequence.
3998
+ if (typeVar && type->isAny ()) {
3999
+ auto *GP = typeVar->getImpl ().getGenericParameter ();
4000
+ if (auto *GPD = GP->getDecl ()) {
4001
+ auto *DC = GPD->getDeclContext ();
4002
+ if (DC->isTypeContext () && DC->getSelfInterfaceType ()->isEqual (GP))
4003
+ return SolutionKind::Error;
4004
+ }
4005
+ }
4006
+
3990
4007
if (auto *fix =
3991
4008
fixRequirementFailure (*this , type, protocolTy, anchor, path)) {
3992
4009
if (!recordFix (fix)) {
0 commit comments