-
Notifications
You must be signed in to change notification settings - Fork 2.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
[SE-0438] Metatype Keypaths #2420
Conversation
proposals/NNNN-metatype-keypath.md
Outdated
@@ -0,0 +1,123 @@ | |||
# Metatype Keypaths | |||
|
|||
* Proposal: [SE-NNNN](NNNN-filename.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amritpan Could you set a name here to NNNN-metatype-keypaths.md
?
proposals/NNNN-metatype-keypath.md
Outdated
let kpWithLiteral = \Bee.Type.name // key path literal \Bee.Type | ||
``` | ||
|
||
Attempting to write the above metatype keypath without including `.Type will trigger an error diagnostic: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing after
Type`
proposals/NNNN-metatype-keypath.md
Outdated
Attempting to write the above metatype keypath without including `.Type will trigger an error diagnostic: | ||
|
||
``` | ||
let kpWithLiteral = \Bee.name // error: static member 'name' cannot be used on instance of type 'Bee' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay to just have error: ...
here without the code.
proposals/NNNN-metatype-keypath.md
Outdated
``` | ||
### Access semantics | ||
|
||
Immutable static properties will form the read-only keypaths just like immutable instance properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be something like - Metatype key paths share almost all access semantics with instance member key paths with a notable exception to mutable static properties - such properties always form ReferenceWritableKeyPath
because their base type (a metatype type) always has reference semantics.
There are 2 notable updates to this proposal (compared to the original pitch) after working through the implementation.
Metatype keypaths are back deployable. Modules/libraries using older compilers will not need to re-compile to see correct operator comparison results. (The entire Implications on adoption section in the pitch is no longer an issue). For reference: Static properties in older modules/libraries will be missing property descriptors when they are referenced via keypath in a module using a compiler with this feature implementation. However, we discovered that the missing property descriptors fortunately did not affect Equatable/Hashable conformance in the Standard Library.
Diagnostics will show an error message if
.Type
is left out of a metatype keypath reference (where the first component is a static property), but a fix-it is not possible at this time.I have left the pitch text intact but the above discoveries are reflected in the proposal text.