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

Clarify library limitations on 'Class modifiers reference' #5097

Open
vladasp opened this issue Aug 8, 2023 · 2 comments
Open

Clarify library limitations on 'Class modifiers reference' #5097

vladasp opened this issue Aug 8, 2023 · 2 comments
Labels
a.language Relates to the Dart language tour act.question Relates to issues that writers need SME help e0-minutes Can complete in < 60 minutes of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged

Comments

@vladasp
Copy link

vladasp commented Aug 8, 2023

Page URL

https://dart.dev/language/modifier-reference.html

Page source

https://github.com/dart-lang/site-www/tree/main/src/language/modifier-reference.md

Describe the problem

Interface class are able to be extended.

The code below has no compilation errors

interface class Base {
  bool someMethod() {
    return Random().nextBool();
  }
}

class ExtendedBase extends Base {
  bool someMthNew() {
    return super.someMethod();
  }
}

class ImplementedBase implements Base {
  @override
  bool someMethod() {
    // TODO: implement someMth
    throw UnimplementedError();
  }
}
@parlough
Copy link
Member

parlough commented Aug 9, 2023

Thanks for opening an issue @vladasp!

As the documentation for the interface modifier specifies "Libraries outside of the interface’s own defining library can implement the interface, but not extend it." The code you included is all in one file, therefore it's all in one library and the interface modifier's limitations do not apply. If you moved ExtendedBase to another file, it should report a diagnostic.

The new class modifiers (base, interface, final, and sealed) all limit specific types of behavior outside of the current library, but not within it. The class modifiers documentation goes into detail.

Let us know if that helps. Thanks again for opening an issue!

\cc @MaryaBelanger Perhaps we should include a small note at the top of the reference that this is the case for some modifiers?

@parlough parlough added a.language Relates to the Dart language tour p2-medium Necessary but not urgent concern. Resolve when possible. e0-minutes Can complete in < 60 minutes of normal, not dedicated, work act.question Relates to issues that writers need SME help labels Aug 9, 2023
@parlough parlough changed the title [PAGE ISSUE]: 'Class modifiers reference' Consider making library limitations clearer on 'Class modifiers reference' Aug 9, 2023
@vladasp
Copy link
Author

vladasp commented Aug 9, 2023

Thanks for opening an issue @vladasp!

As the documentation for the interface modifier specifies "Libraries outside of the interface’s own defining library can implement the interface, but not extend it." The code you included is all in one file, therefore it's all in one library and the interface modifier's limitations do not apply. If you moved ExtendedBase to another file, it should report a diagnostic.

The new class modifiers (base, interface, final, and sealed) all limit specific types of behavior outside of the current library, but not within it. The class modifiers documentation goes into detail.

Let us know if that helps. Thanks again for opening an issue!

\cc @MaryaBelanger Perhaps we should include a small note at the top of the reference that this is the case for some modifiers?

@parlough Thank you for answer and currently it become clear for me.
But it still seems to me that the Reference page should be more precise in this regard. Since the table is provided on the separate page and there is no information that it is only valid outside of the library. In addition, the page structure:
Class modifiers:

  • Overview and usages
  • Class modifiers for API maintainers
  • Reference

contains a separate item for API maintainers, which suggests that only this particular section describes behaviour outside the library.

@atsansone atsansone changed the title Consider making library limitations clearer on 'Class modifiers reference' Clarify library limitations on 'Class modifiers reference' Aug 21, 2023
@atsansone atsansone added the st.triage.ltw Indicates Lead Tech Writer has triaged label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.language Relates to the Dart language tour act.question Relates to issues that writers need SME help e0-minutes Can complete in < 60 minutes of normal, not dedicated, work p2-medium Necessary but not urgent concern. Resolve when possible. st.triage.ltw Indicates Lead Tech Writer has triaged
Projects
None yet
Development

No branches or pull requests

3 participants