[swift-evolution] What about a VBA style with Statement?

Erica Sadun erica at ericasadun.com
Wed Apr 13 11:48:48 CDT 2016


> On Apr 13, 2016, at 10:32 AM, Vladimir.S <svabox at gmail.com> wrote:
> 
> But in case of struct instance constant - we have a problem:
> 
> struct A {
>    var x = 1
>    var y = 2
> }
> 
> let a1 = A()
> 
> with (a1) {
>    print($0.x)
>    $0.y = 10
> }
> 
> - this will be compiled without errors/warnings, but yes - there will be runtime error. I'm sure this is not what we need from Swift. And so, this "with" function can not be a 100% replacement for special language construction. So, all, please provide your opinion on this proposal and I believe we should move it forward.
> 
> 

My version of `with` doesn't have this issue. However, it's a clear logical error on the programmer's part when you treat a value type as a reference type.

-- E


More information about the swift-evolution mailing list