In the following example I get a compile error for the variable deferredAssignment at compile time:
Cannot assign value of type 'GenericClass' to type 'some Generic'
whereas inline assignment succeeds. Am I missing something?
protocol Generic {
func getSelf() -> Self
}
class GenericClass: Generic {
func getSelf() -> Self { return self }
}
class GenericChildClass: GenericClass {
override func getSelf() -> Self { return self }
}
var inlineAssignment: (some Generic)? = GenericClass() // This compiles fine
var deferredAssignment: (some Generic)?
deferredAssignment = GenericClass() //Cannot assign value of type 'GenericClass' to type 'some Generic'