What changed with AdditiveArithmetic in 5.2?

I have a package with the following type structure:

protocol ErasedProtocol { }
extension ErasedProtocol {
    public static func +(lhs: Self, rhs: Self) -> Self { }
    // implementation for -, /, *

    public static func +=(lhs: inout: Self, rhs: Self) { }
    // implementation for -=, /=, *=
}

protocol _Implementation: ErasedProtocol, AdditiveArithmetic { }

struct Implementation: _Implementation { }

Now, with Swift 5.1 and before - this compiles and I'm able to use all of the various operators with no problems.

However, with Swift 5.2 (snapshot from Jan 16, 2020), I get the following errors:

  1. Multiple matching functions named '+=' with type '(inout Implementation, Implementation) -> ()
  2. Candidate matches exactly (clicking on this in Xcode takes me to my default implementations for -=, etc.

If I remove my default implementations for the inout form, when I use them in unit tests I get the following compile error:
Protocol 'FloatingPoint' requires that 'Implementation' conform to 'FloatingPoint'

This is specifically in cases of /= and *=.

So what changed in 5.2?

Obviously, as soon as I drop the requirement of _Implementation: AdditiveArithmetic with no other code changes, everything compiles and runs as expected.

Terms of Service

Privacy Policy

Cookie Policy