Skip to content

Commit

Permalink
[extension types] Specify that a method shadows an "inherited" setter…
Browse files Browse the repository at this point in the history
…, and vice versa (#3470)

This PR changes the extension types feature specification such that a method declaration in an extension type will shadow an "inherited" setter, and vice versa. This eliminates a setter/method conflict which couldn't otherwise be resolved.
  • Loading branch information
eernstg authored Nov 19, 2023
1 parent 2edfa84 commit 299d20b
Showing 1 changed file with 48 additions and 10 deletions.
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.31
- Simplify the rules about the relationship between extension types and the
types `Object` and `Object?`.
Expand Down Expand Up @@ -516,14 +521,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 @@ -534,10 +568,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

0 comments on commit 299d20b

Please sign in to comment.