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

Update class modifiers specification. #2889

Merged
merged 8 commits into from
Mar 28, 2023
Merged

Update class modifiers specification. #2889

merged 8 commits into from
Mar 28, 2023

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Mar 6, 2023

  • Tighten the modifiers implied on anonymous mixin class applications.
  • Claim that enum declarations are final.
  • Allow pre-feature libraries to mix in platform no-mixin classes if they could before.
  • A little rephrasing, to allow reusing a concept.

But do not allow interface mixin class etc. anyway.

@munificent @kallentu

@lrhn lrhn requested a review from eernstg March 6, 2023 14:38
Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

LGTM! A couple of comments added.

@leafpetersen
Copy link
Member

For the record, I continue to think this is a mistake, for all the reasons laid out in #2723 .

Copy link
Member

@leafpetersen leafpetersen left a comment

Choose a reason for hiding this comment

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

I am very much not on board with this change. If we actually feel that we need to ability to have variants of these that can be mixed in internally but not externally, we should instead remove the restriction that you cannot mix in a class which is not marked as mixin inside of your own library.

@lrhn
Copy link
Member Author

lrhn commented Mar 9, 2023

Reverted the change to allow interface mixin class.

PTAL

* Allow `interface mixin class` etc.
* Tighten the modifiers implied on anonymous mixin class applications.
* A little rephrasing, to allow reusing a concept.
But do allow mixing in non-mixin platform classes from pre-feature libraries.
Fix grammatical cases.
Copy link
Member

@leafpetersen leafpetersen left a comment

Choose a reason for hiding this comment

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

This looks great, thank you!

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

I Indicated a handful of typo level issues (syntax errors in examples and such).

More importantly, the definition of 'prohibits inheritance' talks about 'declarations', and the actual wording of subsequent lines does not make sense unless we count each anonymous mixin application as a 'declaration' and consider that declaration to be 'marked with' each of its implicitly induced modifiers.

However, I still think the rules about anonymous mixin applications are simpler to understand if they are expressed directly in terms of the class modifiers (sealed as well as final/base/interface/none, explicitly specified as well as implicitly induced), so I inserted a 'suggestion' about how that could be done.

// These are valid, but cannot be implemented locally:
sealed class DE extends S {}
final class DM with S {}
base mixin MO on S {}
Copy link
Member

Choose a reason for hiding this comment

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

It seems worthwhile to show that a mixin on S is usable, and to mention that the resulting class also cannot be implemented locally.

Suggested change
base mixin MO on S {}
base mixin MO on S {}
final class DMO extends DM with MO {}

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

Couple of comments.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Mar 22, 2023
As of dart-lang/language#2889 it is an error
to declare a mixin with an `on` type which is declared in a different
library.

Change-Id: I02d6b3b6c203a46c74d2eacd006181db8e563726
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290022
Reviewed-by: Kallen Tu <kallentu@google.com>
@lrhn lrhn merged commit 4f5e228 into master Mar 28, 2023
@lrhn lrhn deleted the v16 branch March 28, 2023 20:44
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.

None yet

7 participants