"Candidate would match if"...class-constrained protocol issue

I was unable to find a post that discussed this exact issue, I think this might be a bug, but I'm unsure:

// Error: Type 'SomeClass' does not conform to protocol 'SomeProtocol'
class SomeClass: SomeProtocol { }

protocol SomeProtocol: SomeClass {
    var someProperty: Int { get }
}

// Note: Candidate would match if 'SomeClass' conformed to 'SomeProtocol'
extension SomeProtocol {
    var someProperty: Int { 0 }
}

Also, if I throw a base-class into the mix, there is no issue:

class SomeBaseClass { }

class SomeClass: SomeBaseClass, SomeProtocol { }

// No error if the protocol is constrained to the base class.
protocol SomeProtocol: SomeBaseClass {
    var someProperty: Int { get }
}

extension SomeProtocol {
    var someProperty: Int { 0 }
}

This isn't really causing me a problem as I can work around it, I'm just curious, the note in particular reads very strangely, since it basically says this default implementation would match if the class conformed to the protocol, but afaict the class does conform to the protocol.

I guess it was a bug. On the current master compiler, your first snippet compiles fine without any errors.

Well, that answers that, thanks for looking into it!

Update: This appears to be resolved in beta 5 :slight_smile:

1 Like
Terms of Service

Privacy Policy

Cookie Policy