Stating aliased type explicitly during pattern variable binding gives me an error

This code gives me the commented error:

struct T { }

public typealias Alias<S> = Result<S, NSError>

let response: Alias<T> = .success(T())

if case let Alias.success(value) = response { // ❌ Operator function '~=' requires that 'T' conform to 'Equatable'
    print("\(value)")
}

However, if I change the pattern variable binding to the following, it compiles just fine:

if case let .success(value) = response { // ✅ works
    print("\(value)")
}

If I forego the type alias I also get no problems:

struct T { }

let response: Result<T, Error> = .success(T())

if case let Result.success(value) = response { // ✅ works
    print("\(value)")
}

I don't understand why stating the type Alias explicitly would give me this error.

1 Like

More weirdness:


Compiles:

if case Alias<T>.success(let value) = response {

Operator function '~=' requires that 'T' conform to 'Equatable':

if case Alias.success(let value) = response {
if case (Alias<T>).success(let value) = response {

'>' is not a postfix unary operator:

if case let (Alias<T>).success(value) = response {
if case let Alias<T>.success(value) = response {
2 Likes
Terms of Service

Privacy Policy

Cookie Policy