Skip to content

Commit 299d20b

Browse files
authored
[extension types] Specify that a method shadows an "inherited" setter, 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.
1 parent 2edfa84 commit 299d20b

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

accepted/future-releases/extension-types/feature-specification.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ information about the process, including in their change logs.
1515
[1]: https://github.com/dart-lang/language/blob/master/working/1426-extension-types/feature-specification-views.md
1616
[2]: https://github.com/dart-lang/language/blob/master/working/extension_structs/overview.md
1717

18+
2023.11.14
19+
- Specify that a method declaration will shadow an otherwise "inherited"
20+
setter with the same basename, and vice versa. This eliminates a
21+
method/setter conflict that would otherwise be impossible to avoid.
22+
1823
2023.10.31
1924
- Simplify the rules about the relationship between extension types and the
2025
types `Object` and `Object?`.
@@ -516,14 +521,43 @@ type declaration, but this section is concerned with invocations of
516521
extension type members.*
517522

518523
We need to introduce a concept that is similar to existing concepts
519-
for regular classes.
524+
for regular classes, namely that an extension type _has_ a certain member.
525+
526+
First, we say that an extension type member declaration _DM_ _precludes_ an
527+
extension type member declaration _DM2_ if they have the same name, or the
528+
basename of _DM_ is the same as the basename of _DM2_, and one of _DM_ and
529+
_DM2_ is a setter declaration, and the other is a method declaration.
530+
531+
Moreover, we say that an extension type member declaration _DM_ _precludes_
532+
a non-extension type member signature `m` if they have the same name, or
533+
the basename of _DM_ is the same as the basename of `m`, and _DM_ is a
534+
setter declaration and `m` is a method signature, or _DM_ is a method
535+
declaration and `m` is a setter signature.
536+
537+
*We use this concept with superinterfaces of DM. DM may have multiple
538+
non-extension type superinterfaces, and they may differ with respect to the
539+
precise member signature for a given member name, but they will not differ
540+
with respect to the kind: `m` may be a method or a setter or a getter, but
541+
it cannot be, e.g., a method in one superinterface and a getter in another
542+
one. Hence, it is well-defined to talk about `m` being a method or a setter
543+
signature even though there may be multiple member signatures with the
544+
given name.*
520545

521546
We say that an extension type declaration _DV_ _has_ an extension type
522-
member named `n` in the case where _DV_ declares a member named `n`, and in
523-
the case where _DV_ has no such declaration, but _DV_ has a direct
524-
extension type superinterface `V` that has an extension type member named
525-
`n`. In both cases, when this is unique, _the extension type member
526-
declaration named `n` that DV has_ is said declaration.
547+
member named `n` in the cases where:
548+
549+
- _DV_ declares a member named `n`.
550+
- _DV_ has no such declaration, but _DV_ has a direct extension type
551+
superinterface `V` that has an extension type member named `n` due to a
552+
member declaration _DM2_, and _DV_ does not declare a member that
553+
precludes _DM2_.
554+
555+
*Note that it is well-defined which member declaration causes an extension
556+
type to have a given extension type member because a compile-time error
557+
occurs whenever this is ambiguous: Either _DV_ contains a declaration
558+
named `n`, or at most one superinterface has an extension type member named
559+
`n`, which is then (by induction) due to a uniquely determined
560+
extension type member declaration.*
527561

528562
The type (function type for a method, return type for a getter) of this
529563
declaration relative to this invocation is determined by repeatedly
@@ -534,10 +568,14 @@ type parameters of the extension type into the type of that declaration.
534568

535569
Similarly, we say that an extension type declaration _DV_ _has_ a
536570
non-extension type member named `n` in the case where _DV_ does not declare
537-
a member named `n`, but _DV_ has a direct extension type superinterface `V`
538-
that has a non-extension type member named `n`, or _DV_ has a direct
539-
non-extension type superinterface `T` whose interface contains a member
540-
signature named `n`.
571+
a member named `n`, and one of the following criteria is satisfied:
572+
573+
- _DV_ has a direct extension type superinterface `V` that has a
574+
non-extension type member with signature `m` and name `n`, and _DV_ does
575+
not declare a member that precludes `m`.
576+
- _DV_ has a direct non-extension type superinterface whose interface
577+
contains a member signature `m` named `n`, and _DV_ does not declare a
578+
member that precludes `m`.
541579

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

0 commit comments

Comments
 (0)