title: Problem passing from a static method a created instance of a subtype to a closure
body: <p>My idea is in a base class's static method to create an instance of a subtype and then pass it as a parameter of the <strong>created type</strong> to a provided closure:</p>
  <pre><code>let subtypeInstance = SubType.baseCreateInstanceOfSubtype() { new in // `new` is expected to be of type `SubType` which declares a property `v`
      new.v = 1
  }
  </code></pre>
  <p>Here's a full example of implementation:</p>
  <pre><code>class Foo {
      required init() {}
      static func createSubtype(initialize: (Self) -&gt; Void) -&gt; Self {
          let foo = Self()
          initialize(foo)
          return foo
      }
  }
  
  class Bar: Foo {
      var v: Int?
  }
  
  let bar = Bar.createSubtype() { o in
      o.v = 1
  }
  
  </code></pre>
  <p>Doing that the Swift compiler yields an error <code>Value of type 'Self' has no member 'v'</code>.
  <code>print(type(of: o))</code> in the closure gives <code>Bar</code>. Adding explicit casting of <code>o</code> to <code>Bar</code>, <code>(o as! Bar).v = 1</code>, solves the problem, but I don't understand why it doesn't work without the explicit casting while the type of <code>o</code> seems to be correct.
  Thanks.</p>