[Pitch] Extend protocol conformance to consider implicitly defined method signatures

Currently, this code will produce a “Type ‘Class’ does not conform to ‘Protocol’” error:

protocol Protocol: class {
    init()
}

class Class: Protocol {
    let number: Int

    init(number: Int = 5) {
        self.number = number
    }
}

In the example above, it seems to me Class should conform to Protocol as it can be initialized with zero arguments. A class should conform to the protocol if the set of functions it defines is a superset of those in the protocol; that is, Class C should conform to Protocol P if C can by typecast to P. In this case, even though Class does not explicitly define an init method with zero parameters, it implicitly does so with the default argument.

1 Like

The actual issue here is the way that default arguments are handled. Right now the default arguments are just sugar for calling the function with the default values. This is semantically correct for direct calls, but not when used in other contexts.

See the previous discussion.

I also opened a pitch about that issue a while ago, it's a class issue.

Writing required convenience override init isn't fun.