Can't get conditional conformance to compile, it can't be applied to the two operands

Trying out a classic computer-science list type:

enum ClassicList<Element> {
    case empty
    indirect case nonempty(head: Element, tail: ClassicList)

Tried adding conditional Equatable conformance:

extension ClassicList: Equatable where Element: Equatable {

    static func == (lhs: ClassicList, rhs: ClassicList) -> Bool {
        switch (lhs, rhs) {
        case (.empty, .empty):
            return true
        case (.nonempty(let leftHead, let leftTail), .nonempty(let rightHead, let rightTail)):
            return leftHead == rightHead && leftTail == rightTail
            return false


But the test (in a separate file) doesn't work:

func testEquality() {
    let e = ClassicList<Int>.empty
    XCTAssertTrue(e == e)

The assertion line has an "Binary operator '==' cannot be applied to two 'ClassicList<Int>' operands" error on it. Why? How can I fix it?

I'm on Xcode 9.3.1 on a High Sierra system, with a "Cocoa Framework" project.

If ClassicList is inside your main module and the test is a unit test target you either not doing @testable import or just make the static func public (and the type?). Your code works in playground as expected.

Already doing both (@testable import and public operator). It’s a standard default “Cocoa Framework” project and I used the standard “New File…” option to create the source and test files.

Another update: I took out the Equatable conformance and tried an (unconditional) IteratorProtocol conformance. The compiler had no issues with the source file, but the testing file complained that my argument to IteratorSequence didn’t have a type conforming to IteratorProtocol.

It’s weird because my first attempts, adding CustomStringConvertible and CustomDebugStringConvertible conformance, compile and test just fine!

Well I‘m running out of ideas. From my point of view it should just work.

Have you tried setting up a different project to test it?
If you‘re using multiple targets for the main module, check if the files where the type is declared and the extension is in are associated with the target module you‘re importing into the unit test module.
If it does not help, try moving the extension into the declaration file and retry.

If nothing resolves the issue then it‘s a bug. You can file it on

[This is from before seeing @DevAndArtist’s second message.]

I wanted to work on something else, and I made a second source file and second test file. That test file doesn’t even see the type from the source file. Something about my project settings/file is fried, and I don’t know what (or where to look).

I switched to creating projects with the Swift Package Manager, and the Xcode project files created from those are working just fine,