I personally find it kind of weird that `let x = 0; do { let x = x + 1 }` is
disallowed but `let x: Int? = 0; if let x = x { }` is allowed. The former case
requires you first rename the variable you plan to shadow, inconveniently:
```
let x = 0
do {
let tempX = x // ew
let x = tempX + 1
}
```
> On Jan 30, 2017, at 11:56 AM, Robert Widmann via swift-evolution
> <[email protected]> wrote:
>
> 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
>> <[email protected] <mailto:[email protected]>> 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?
>>
>>
>> Thanks,
>> Michael Gubik
>>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution