Skip to content
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-NNNN] Metatype Keypaths #2420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

amritpan
Copy link
Member

@amritpan amritpan commented Apr 25, 2024

There are 2 notable updates to this proposal (compared to the original pitch) after working through the implementation.

  1. 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.

  2. 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.

@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Apr 29, 2024
@@ -0,0 +1,123 @@
# Metatype Keypaths

* Proposal: [SE-NNNN](NNNN-filename.md)
Copy link
Member

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?

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing afterType`

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'
Copy link
Member

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.

```
### Access semantics

Immutable static properties will form the read-only keypaths just like immutable instance properties.
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
3 participants