[swift-evolution] Why doesn't Swift allow a variable and a function with the same name?
devteam.codafi at gmail.com
Mon Jan 30 13:56:15 CST 2017
This seems like it’s running through the same check that disallows defining and calling a closure
let randomFunc : () -> () = randomFunc()
> On Jan 30, 2017, at 2:37 PM, Michael Gubik via swift-evolution <swift-evolution at swift.org> wrote:
> Example that does not compile:
> let randomArray = randomArray(withCapacity: 4096)
> Compiler error: “Variable used within its own initial value”
> The variable name unfortunately clashes with the function name.
> This problem forces the developer to think about an alternative name.
> IMHO that’s suboptimal since many times the most canonical naming would be one where these two go by the same name.
> It’s not a big problem in practice but I wonder if there are plans to change this?
> Michael Gubik
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution