Conforming Generic to Equatable from a Test target

Hello

I’m trying to extend a generic with Equatable on the Test target.

App-side code :

struct Container<Containee> {}

Test-side code :

extension Container: Equatable where Containee: Equatable {
    public static func == (lhs: Container<Containee>, rhs: Container<Containee>) -> Bool {
          /* my logic */
    }
}

But the compiler keeps pushing this error :
Cannot declare a public operator function in an extension with internal requirements
Equatable requires me to set the operator as public so i'm confused...

Someone over a Slack channel told me he had the same issue and he thought it was related to @testable

All members of a module are implicitly internal.

In your case, Equatable requires Container to be explicitly public:

public struct Container <Containee> { <#...#> }

(Edit: apparently this is a bug, see below.)

I have no problem extending other struct the same way.
It only occurs when the struct is a generic.
Adding public to my struct doesn't solve the issue.

Confirming that this is a bug: @testable import allows you to access internal things from your app, and that should include the generic parameters. (Thanks for filing it on bugs.swift.org.)

2 Likes