-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-10135] Property with type 'Self' cannot override a property with type 'Self' #52537
Comments
Totally reasonable as long as it's a read-only property. I'm not quite going to tag this as a starter bug because I'm not sure what all the moving pieces would be, but I don't think it would be too hard. |
Maybe this is basic stuff, but... if the subclass B had properties (e.g. var foo: Int = 0) and B().copy() instantiates parent A, which doesn't have foo property and only casts it to B, how come code doesn't crash on runtime when you do e.g. B().copy().foo = 5? |
Comment by LinQingmo (JIRA) @Moximillian It will not crash. func copy() -> Self {
let copy = Self.init() // When call B().copy(), this is let copy = B.init(), so it can cast to B.
print(type(of: copy)) // When call B().copy(), the type of copy is B not A.
return copy
} |
Right, the |
Oh, inherited methods operate on instance of subclass, so is more similar to protocol extension, in a way... All makes sense now, thanks! |
PR filed to make declaring properties of type `Self` an error: #23485 |
Environment
Swift Development Snapshot 2019-03-17
Additional Detail from JIRA
md5: e8e72fa6406e42baa338fec2b7c90afe
Issue Description:
The text was updated successfully, but these errors were encountered: