title: Why is static property's closure executed on assignment?
body: <p>Static properties in swift are initialised lazily. I wanted to use a static property of a class as a dependency that I could easily replace while doing a unit test. The value of the property was immediately invoked closure, but I expected this closure to never execute if I replace the property without ever reading it.</p>
  
  <p>However upon setting the static property, the original closure gets executed. It's not the case for lazy instance properties. Why is that?</p>
  
  <p>To illustrate the issue, I have provided a sample code.</p>
  
  <p>The output of this code:</p>
  
  <pre><code>class Foo {
      static var bar1: String = {
          print("here we are")
          return "This is static bar"
      }()
  
      lazy var bar2: String = {
          print("here we are too")
          return "This is instance bar"
      }()
  }
  
  let foo = Foo()
  print("We have a Foo instance")
  Foo.bar1 = "Overwritten bar 1"
  print(Foo.bar1)
  foo.bar2 = "Overwritten bar 2"
  print(foo.bar2)
  </code></pre>
  
  <p>is:</p>
  
  <pre><code>We have a Foo instance
  here we are
  Overwritten bar 1
  Overwritten bar 2
  </code></pre>