Yes, IMO it really looks strange.
Just checked:

    class Foo {
        static var test = "test"

        static var bar: String = {
            print("static")
            return "Default"
        }()

        lazy var baz: String = {
            print("lazy")
            return "Lazy"
        }()
    }


    print("1")
    print(Foo.test)
    print("2")
    Foo.bar = "Set"
    print("3")
    let foo = Foo()
    foo.baz = "Set"
    print("4")

we have :
1
test
2
static
3
4

I strongly believe as static property is lazy by definition, it must not be evaluated at all when we set it. This is something that "lazyness" promises to us - that it will be called/calculated ONLY when we ask for this. So in my opinion this is bug/issue and should be fixed/changed in Swift 3.0.


On 08.04.2016 10:36, David Rönnqvist via swift-evolution wrote:
I noticed a difference between how static and lazy variables evaluate closures 
and thought that it was a bug:
https://bugs.swift.org/browse/SR-1178
but apparently it’s not.
> ...
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to