[swift-evolution] [Proposal draft #2] Naming Functions with Argument Labels
dgregor at apple.com
Tue Jan 12 12:20:23 CST 2016
> On Jan 11, 2016, at 11:52 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>>>> It’s grammatically ambiguous if you don’t have the “:)” at the end
>>> Is it? It's not legal to pass a type name—`foo(bar: Int)` is not legal code; you have to say `foo(bar: Int.self)`.
>> "Grammatically" is key here: the parser doesn't know a type name from a variable name.
> Okay, but is it important to distinguish the two grammatically? A function call and a function reference are both expressions and can (types aside) both be used in the same places, right?
IMO, it’s important to distinguish them grammatically. Yes, one could potentially make the type checker sort it out, but it adds significant complexity to the feature and the compiler, for the benefit of a small corner case that could be handled via type context already. Moreover, it means that we wouldn’t be able to take this currently-invalid code
and correct it to
which is almost surely what the user meant (the “.self” rule is a tricky one to remember).
More information about the swift-evolution