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] Specify that a method shadows an "inherited" setter, and vice versa #3470

Merged
merged 8 commits into from
Nov 19, 2023
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions accepted/future-releases/extension-types/feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ information about the process, including in their change logs.
[1]: https://github.com/dart-lang/language/blob/master/working/1426-extension-types/feature-specification-views.md
[2]: https://github.com/dart-lang/language/blob/master/working/extension_structs/overview.md

2023.11.14
- Specify that a method declaration will shadow an otherwise "inherited"
setter with the same basename, and vice versa. This eliminates a
method/setter conflict that would otherwise be impossible to avoid.

2023.10.25
- Allow an extension type to have `implements T` where `T` is a
supertype of the representation type (the old rule only allows
Expand Down Expand Up @@ -512,14 +517,43 @@ type declaration, but this section is concerned with invocations of
extension type members.*

We need to introduce a concept that is similar to existing concepts
for regular classes.
for regular classes, namely that an extension type _has_ a certain member.

First, we say that an extension type member declaration _DM_ _precludes_ an
extension type member declaration _DM2_ if they have the same name, or the
basename of _DM_ is the same as the basename of _DM2_, and one of _DM_ and
_DM2_ is a setter declaration, and the other is a method declaration.

Moreover, we say that an extension type member declaration _DM_ _precludes_
a non-extension type member signature `m` if they have the same name, or
the basename of _DM_ is the same as the basename of `m`, and _DM_ is a
setter declaration and `m` is a method signature, or _DM_ is a method
declaration and `m` is a setter signature.

*We use this concept with superinterfaces of DM. DM may have multiple
non-extension type superinterfaces, and they may differ with respect to the
precise member signature for a given member name, but they will not differ
with respect to the kind: `m` may be a method or a setter or a getter, but
it cannot be, e.g., a method in one superinterface and a getter in another
one. Hence, it is well-defined to talk about `m` being a method or a setter
signature even though there may be multiple member signatures with the
given name.*

We say that an extension type declaration _DV_ _has_ an extension type
member named `n` in the case where _DV_ declares a member named `n`, and in
the case where _DV_ has no such declaration, but _DV_ has a direct
extension type superinterface `V` that has an extension type member named
`n`. In both cases, when this is unique, _the extension type member
declaration named `n` that DV has_ is said declaration.
member named `n` in the cases where:

- _DV_ declares a member named `n`.
- _DV_ has no such declaration, but _DV_ has a direct extension type
superinterface `V` that has an extension type member named `n` due to a
member declaration _DM2_, and _DV_ does not declare a member that
precludes _DM2_.

*Note that it is well-defined which member declaration causes an extension
type to have a given extension type member because a compile-time error
occurs whenever this is ambiguous: Either _DV_ contains a declaration
named `n`, or at most one superinterface has an extension type member named
`n`, which is then (by induction) due to a uniquely determined
extension type member declaration.*

The type (function type for a method, return type for a getter) of this
declaration relative to this invocation is determined by repeatedly
Expand All @@ -530,10 +564,14 @@ type parameters of the extension type into the type of that declaration.

Similarly, we say that an extension type declaration _DV_ _has_ a
non-extension type member named `n` in the case where _DV_ does not declare
a member named `n`, but _DV_ has a direct extension type superinterface `V`
that has a non-extension type member named `n`, or _DV_ has a direct
non-extension type superinterface `T` whose interface contains a member
signature named `n`.
a member named `n`, and one of the following criteria is satisfied:

- _DV_ has a direct extension type superinterface `V` that has a
non-extension type member with signature `m` and name `n`, and _DV_ does
not declare a member that precludes `m`.
- _DV_ has a direct non-extension type superinterface whose interface
contains a member signature `m` named `n`, and _DV_ does not declare a
member that precludes `m`.

The member signature of such a member is the combined member signature of
all non-extension type members named `n` that _DV_ has, again using a
Expand Down