Referring to failable initializer with leading dot syntax

The rule for leading dot syntax is that it will look in the contextual type for a method/initializer/case whose result type is identical to that type. That means it can't find failable initializers: if it looked for them on Foo, it would find a result type of type Foo?, and if it looked for them on Optional, it wouldn't find them at all.

That said, Optional is already magic treated specially in various parts of the language—failable initializers being one of them—and so it might be reasonable to extend the rule to allow cases like this. I'm not sure how much work that would be in the type checker, though.

5 Likes