[SR-14344] Problem passing from a static method a created instance of a subtype to a closure with Self-type parameter #56703
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: 9b7b59504609eef81f65b6cb2d22684a
Issue Description:
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 created type to a provided closure:
class Foo {
{{ required init() {}}}
{{ class func createSubtype(initialize: (Self) -> Void) -> Self {}}
{{ let new = Self()}}
{{ initialize(new)}}
{{ return new}}
{{}}}
class Bar: Foo {
{{ var v: Int?}}
}
let bar = Bar.createSubtype() { new in
{{ new.v = 1}}
{{}}}
Doing that the Swift compiler yields an error Value of type 'Self' has no member 'v'. But '
print(type(of: o))
' in the closure gives 'Bar
'. According to [Expanding Swift Self to class members and value types|https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md] implemented in Swift 5.1 using 'Self
' should be appropriate here.The text was updated successfully, but these errors were encountered: