Introduce Any<P> as a better way of writing existentials

I like this idea a lot, where partial is only needed when the protocol type does not conforms to itself. I think the compiler should emit a warning and a fixit to remove partial whenever you have enough constrains to have the protocol type starts conforming to itself, and another to add partial (or specify constraints) when not conforming to itself.


And this now has a meaningful error message:

func test(a: partial Equatable, b: partial Equatable) -> Bool {
    a == b // error: partial Equatable has no ==
}

Someone's reaction could be to remove partial from the parameter types, which should get the compiler to propose adding constraints:

func test(a: Equatable, b: Equatable) -> Bool {
    // warning: Equatable needs constraints or should be labeled as partial
    // fix: add `partial`
    // fix: add `where Self == X` constraint
    a == b
}

Not that there's much that can be done in a situation like this, but at least it lets the user know that Self needs to be bound for the protocol to be usable.


And perhaps in the future we'll be able to write:

extension partial Equatable: Equatable {
    static func ==(a: Equatable, b: Equatable) { ... }
}

and it'd make partial Equatable conform to Equatable, which means you no longer need to write partial. This is why the == function here uses Equatable.

2 Likes