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

Extension types feature specification #3182

Merged
merged 29 commits into from
Jul 21, 2023
Merged

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Jun 30, 2023

This PR is a proposal for how we could specify extension types, following up on the discussions it the language team this week.

cc @dart-lang/language-team

@eernstg
Copy link
Member Author

eernstg commented Jun 30, 2023

It includes the special case of the primary constructor syntax, and it makes this syntax required (it's a syntax error to not have it). It allows non-extension-type superinterfaces as long as they are supertypes of the representation type.

As a thought experiment (which we could take seriously), it does not make the representation name available as a getter. This means that the representation object is treated, as we've mentioned in various discussions, as a name which is in scope in the extension type body but not accessible from anywhere else (just like type parameters).

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

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

FWIW, I think this proposal would be much less confusing to users than the inline classes proposal. In particular I think the semantics of both redeclaration and fields are far less surprising.

@eernstg
Copy link
Member Author

eernstg commented Jul 7, 2023

Just landed a commit that drops the special exception whereby e.id is an error when id is the representation name and e isn't this. In other words, we're dropping the lexical-scope-only rule, the representation declaration works just like any other getter now. If the developer wishes to prevent direct access (at least from other libraries), the representation name should be private.

Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

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

Got to line 915.

Author: eernst@google.com

Status: Accepted.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@lrhn lrhn Jul 10, 2023

Choose a reason for hiding this comment

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

(I'm slighlty split here. Motivating examples are nice for getting things accepted, but once accepted, I'd like a tight, sharp specification the of what the feature does, without motivation or discussions about alternatives. Just the facts.

Could we split it in two files? Motivation/discussion and specification. If the specification doesn't work without the other text, then it's already non self-contained enough.

@eernstg
Copy link
Member Author

eernstg commented Jul 11, 2023

Great feedback, @lrhn! Changed a bunch of things and uploaded.
Didn't do anything about the introductory example, yet.

@eernstg eernstg mentioned this pull request Jul 12, 2023
…dynamic); what it means to "have" (non-)extension type members; add errors (incl implements T); cleaned up duplicated error messages
@eernstg
Copy link
Member Author

eernstg commented Jul 12, 2023

Further revisions have been made now. In particular, a lot of things became simpler by introducing the notion of 'an extension type member' and 'a non-extension type member' maintains the distinction that the declaration of the given member is located in an extension type declaration respectively it is in the interface of a non-extension type superinterface.

So we don't need to re-explain that we need to look up through the superinterface graph in order to see whether any given member came from an extension type or from a non-extension type.

…stant if there is an explicit `const`, otherwise not
@eernstg
Copy link
Member Author

eernstg commented Jul 19, 2023

Just updated the grammar to support const on the primary constructor, and the rules to say that the constructor is constant if and only if const is present in the declaration header.

@eernstg eernstg merged commit bb001dc into main Jul 21, 2023
@eernstg eernstg deleted the spec_extension_types_jun23 branch July 21, 2023 09:24
lrhn pushed a commit that referenced this pull request Jul 21, 2023
Modify the inline class feature specification to specify extension types. This is a feature renaming, but also a reintroduction of a special case of the primary constructor syntax, and an enhancement with support for non-extension type superinterfaces (cf. #3090). Note that many types cannot be used as superinterfaces (including `Function` and function types, records, `T?` for any `T`); we may choose to enable a broader set of types in the future, but at this time we prefer to keep it simple. For instance, `UP` may need to be revised if we accept a broader set of types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants