Skip to content

Commit 227b140

Browse files
committed
Rename on-class to on-declaration (it should fit mixins/enum/extension-types, too)
1 parent 989ffb1 commit 227b140

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

working/0723-static-extensions/feature-specification-variant1.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Version: 1.1
99
Experiment flag: static-extensions
1010

1111
This document specifies static extensions. This is a feature that supports
12-
the addition of static members and/or factory constructors to an existing
12+
the addition of static members and/or constructors to an existing
1313
declaration that can have such members, in a way which is somewhat similar
1414
to the addition of instance members using a plain `extension` declaration.
1515

@@ -48,21 +48,22 @@ void main() {
4848
}
4949
```
5050

51-
A static extension declaration is associated with an _on-class_ (as opposed
52-
to a plain extension declaration which is associated with an on-type). In
53-
the example above, the on-class of `E1` is `Distance`.
51+
A static extension declaration is associated with an _on-declaration_ (as
52+
opposed to a plain extension declaration which is associated with an
53+
on-type). In the example above, the on-declaration of `E1` is `Distance`.
5454

55-
When the on-class of a static extension declaration is a generic class `G`,
56-
the on-class may be denoted by a raw type `G`, or by a parameterized type
57-
`G<T1, .. Tk>`.
55+
When the on-declaration of a static extension declaration is a generic
56+
class `G`, the on-declaration may be denoted by a raw type `G`, or by a
57+
parameterized type `G<T1, .. Tk>`.
5858

59-
When the on-class is denoted by a raw type, the static extension cannot
60-
declare any constructors, it can only declare static members. In this case
61-
the type arguments of the on-class are ignored, which is what the `static`
62-
members must do anyway.
59+
When the on-declaration is denoted by a raw type, the static extension
60+
cannot declare any constructors, it can only declare static members. In
61+
this case the type arguments of the on-declaration are ignored, which is
62+
what the `static` members must do anyway.
6363

64-
When the on-class is denoted by a parameterized type `T`, constructors in the
65-
static extension must return an object whose type is `T`.
64+
When the on-declaration is denoted by a parameterized type `T`,
65+
constructors in the static extension must return an object whose type is
66+
`T`.
6667

6768
For example:
6869

@@ -75,7 +76,7 @@ static extension E2 on Map {
7576
}
7677
7778
// Declare extension type parameters, to be used by constructors. The
78-
// type parameters can have stronger bounds than the on-class.
79+
// type parameters can have stronger bounds than the on-declaration.
7980
static extension E3<K extends String, V> on Map<K, V> {
8081
factory Map.fromJson(Map<String, Object?> source) => Map.from(source);
8182
}
@@ -111,8 +112,8 @@ static extension<X extends Comparable<X>> on SortedList<X> {
111112

112113
A static extension with type parameters can be specialized for specific
113114
values of specific type arguments by specifying actual type arguments of
114-
the on-class to be types that depend on each other, or types with no type
115-
variables:
115+
the on-declaration to be types that depend on each other, or types with no
116+
type variables:
116117

117118
```dart
118119
static extension E4<X> on Map<X, List<X>> {
@@ -174,7 +175,7 @@ The grammar is modified as follows:
174175

175176
In a static extension of the form `static extension E on C {...}` where `C`
176177
is an identifier or an identifier with an import prefix, we say that the
177-
on-class of the static extension is `C`.
178+
on-declaration of the static extension is `C`.
178179

179180
If `C` denotes a non-generic class, mixin, mixin class, or extension
180181
type then we say that the _constructor return type_ of the static extension
@@ -185,8 +186,9 @@ If `C` denotes a generic declaration then `E` is treated as
185186
where `T1 .. Tk` are obtained by instantiation to bound.
186187

187188
In a static extension of the form `static extension E on C<T1 .. Tk> {...}`
188-
where `C` is an identifier or prefixed identifier, we say that the on-class
189-
of `E` is `C`, and the _constructor return type_ of `E` is `C<T1 .. Tk>`.
189+
where `C` is an identifier or prefixed identifier, we say that the
190+
on-declaration of `E` is `C`, and the _constructor return type_ of `E` is
191+
`C<T1 .. Tk>`.
190192

191193
In both cases, `E` is an identifer `id` which is optionally followed by a
192194
term derived from `<typeParameters>`. We say that the identifier `id` is
@@ -198,18 +200,18 @@ occurrences of those type parameters.*
198200
At first, we establish some sanity requirements for a static extension
199201
declaration by specifying several errors.
200202

201-
A compile-time error occurs if the on-class of a static extension does not
202-
resolve to an enum declaration or a declaration of a class, a mixin, a mixin
203-
class, or an extension type.
203+
A compile-time error occurs if the on-declaration of a static extension
204+
does not resolve to an enum declaration or a declaration of a class, a
205+
mixin, a mixin class, or an extension type.
204206

205207
A compile-time error occurs if a static extension has an on-clause of the
206208
form `on C` where `C` denotes a generic class and no type arguments are
207209
passed to `C` *(i.e., it is a raw type)*, and the static extension contains
208210
one or more constructor declarations.
209211

210212
*In other words, if the static extension ignores the type parameters of the
211-
on-class then it can only contain `static` members. Note that if the
212-
on-class is non-generic then `C` is not a raw type, and the static
213+
on-declaration then it can only contain `static` members. Note that if the
214+
on-declaration is non-generic then `C` is not a raw type, and the static
213215
extension can contain constructors.*
214216

215217
A compile-time error occurs if a static extension has an on-clause of the
@@ -252,10 +254,10 @@ recommended message:
252254

253255
A compile-time diagnostic is emitted if a static extension _D_ declares a
254256
constructor or a static member with the same basename as a constructor or a
255-
static member in the on-class of _D_.
257+
static member in the on-declaration of _D_.
256258

257259
*In other words, a static extension should not have name clashes with its
258-
on-class.*
260+
on-declaration.*
259261

260262
#### Static extension scopes
261263

@@ -308,7 +310,7 @@ in order to manually resolve a name clash.*
308310
A static member invocation on a class `C`, of the form `C.m()` (or any
309311
other member access), is resolved by looking up static members in `C` named
310312
`m` and looking up static members of every accessible static extension with
311-
on-class `C` and a member named `m`.
313+
on-declaration `C` and a member named `m`.
312314

313315
If `C` contains such a declaration then the expression is an invocation of
314316
that static member of `C`, with the same static analysis and dynamic
@@ -378,7 +380,7 @@ parameters declared by a static extension.
378380

379381
An _explicitly resolved invocation_ of a constructor named `C.name` in a
380382
static extension declaration _D_ named `E` with `s` type parameters and
381-
on-class `C` can be expressed as `E<S1 .. Ss>.C.name(args)`,
383+
on-declaration `C` can be expressed as `E<S1 .. Ss>.C.name(args)`,
382384
`E.C<U1 .. Uk>.name(args)`, or `E<S1 .. Ss>.C<U1 .. Uk>.name(args)`
383385
(and similarly for a constructor named `C` using `E<S1 .. Ss>.C(args)`,
384386
etc).
@@ -420,9 +422,9 @@ them to explicitly resolved ones.*
420422

421423
A constructor invocation of the form `C<T1 .. Tm>.name(args)` is partially
422424
resolved by looking up a constructor named `C.name` in the class `C` and in
423-
every accessible static extension with on-class `C`. A compile-time error
424-
occurs if no such constructor is found. Similarly, an invocation of the
425-
form `C<T1 ... Tm>(args)` uses a lookup for constructors named `C`.
425+
every accessible static extension with on-declaration `C`. A compile-time
426+
error occurs if no such constructor is found. Similarly, an invocation of
427+
the form `C<T1 ... Tm>(args)` uses a lookup for constructors named `C`.
426428

427429
*Note that, as always, a constructor named `C` can also be denoted by
428430
`C.new` (and it must be denoted as such in a constructor tear-off).*

working/0723-static-extensions/feature-specification-variant2.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ void main() {
5050

5151
In the case where the on-type of an extension declaration satisfies some
5252
constraints, we say that the class/mixin/etc. which is referred in the
53-
on-type is the _on-class_ of the extension.
53+
on-type is the _on-declaration_ of the extension.
5454

5555
The enhancements specified for `extension` declarations in this document
56-
are only applicable to extensions that have an on-class, all other
56+
are only applicable to extensions that have an on-declaration, all other
5757
extensions will continue to work exactly as they do today. In the example
58-
above, the on-class of `E1` is `Distance`.
58+
above, the on-declaration of `E1` is `Distance`.
5959

6060
For example:
6161

@@ -131,38 +131,39 @@ The grammar remains unchanged.
131131

132132
However, it is no longer an error to declare a factory constructor
133133
(redirecting or not) or a redirecting generative constructor in an
134-
extension declaration that has an on-class, possibly constant. *Such
135-
declarations may of course give rise to errors as usual, e.g., if a
134+
extension declaration that has an on-declaration, possibly constant.
135+
136+
*Such declarations may of course give rise to errors as usual, e.g., if a
136137
redirecting factory constructor redirects to a constructor that does not
137138
exist, or there is a redirection cycle.*
138139

139140
In an extension declaration of the form `extension E on C {...}` where `C`
140141
is an identifier or an identifier with an import prefix that denotes a
141142
class, mixin, enum, or extension type declaration, we say that the
142-
_on-class_ of the extension is `C`. If `C` denotes a non-generic class,
143-
mixin, mixin class, or extension type then we say that the _constructor
144-
return type_ of the extension is `C`.
143+
_on-declaration_ of the extension is `C`. If `C` denotes a non-generic
144+
class, mixin, mixin class, or extension type then we say that the
145+
_constructor return type_ of the extension is `C`.
145146

146147
If `C` denotes a generic class then `E` is treated as
147148
`extension E on C<T1 .. Tk> {...}` where `T1 .. Tk` are obtained by
148149
instantiation to bound.
149150

150-
In an extension of the form `extension E on C<T1 .. Tk> {...}`
151-
where `C` is an identifier or prefixed identifier that denotes a class,
152-
mixin, enum, or extension type declaration, we say that the _on-class_
153-
of `E` is `C`, and the _constructor return type_ of `E` is `C<T1 .. Tk>`.
151+
In an extension of the form `extension E on C<T1 .. Tk> {...}` where `C`
152+
is an identifier or prefixed identifier that denotes a class, mixin, enum,
153+
or extension type declaration, we say that the _on-declaration_ of `E` is
154+
`C`, and the _constructor return type_ of `E` is `C<T1 .. Tk>`.
154155

155156
In an extension of the form `extension E on F<T1 .. Tk> {...}` where `F` is
156157
a type alias whose transitive alias expansion denotes a class, mixin, enum,
157-
or extension type `C`, we say that the _on-class_ of `E` is `C`, and the
158-
_constructor return type_ of `E` is the transitive alias expansion of
158+
or extension type `C`, we say that the _on-declaration_ of `E` is `C`, and
159+
the _constructor return type_ of `E` is the transitive alias expansion of
159160
`F<T1 .. Tk>`.
160161

161-
In all other cases, an extension declaration does not have an on-class nor a
162-
constructor return type.
162+
In all other cases, an extension declaration does not have an
163+
on-declaration nor a constructor return type.
163164

164-
For the purpose of identifying the on-class and constructor return type of
165-
a given extension, the types `void`, `dynamic`, and `Never` are not
165+
For the purpose of identifying the on-declaration and constructor return
166+
type of a given extension, the types `void`, `dynamic`, and `Never` are not
166167
considered to be classes, and neither are record types or function types.
167168

168169
*Also note that none of the following types are classes:*
@@ -192,13 +193,13 @@ recommended message:
192193

193194
A compile-time diagnostic is emitted if an extension _D_ declares a
194195
constructor or a static member with the same basename as a constructor or a
195-
static member in the on-class of _D_. A similar diagnostic is emitted when
196-
_D_ is an enum, mixin, mixin class, or extension type declaration.
196+
static member in the on-declaration of _D_. A similar diagnostic is emitted
197+
when _D_ is an enum, mixin, mixin class, or extension type declaration.
197198

198199
*In other words, an extension should not have name clashes with its
199-
on-class. The warning above is aimed at static members and constructors,
200-
but a similar warning would probably be useful for instance members as
201-
well.*
200+
on-declaration. The warning above is aimed at static members and
201+
constructors, but a similar warning would probably be useful for instance
202+
members as well.*
202203

203204
#### Invocation of a static member
204205

@@ -242,7 +243,7 @@ pre-feature Dart.*
242243
In the case where `C` does not declare any static members whose basename is
243244
the basename of `m`, and `C` does not declare any constructors named `C.m2`
244245
where `m2` is the basename of `m`, let _M_ be the set containing each
245-
accessible extension whose on-class is `C`, and whose static members
246+
accessible extension whose on-declaration is `C`, and whose static members
246247
include one with the name `m`, or which declares a constructor named `C.m`.
247248

248249
*If `C` does declare a constructor with such a name `C.m2` then the given
@@ -322,8 +323,8 @@ member invocations, but they need more detailed rules because they can use
322323
the formal type parameters declared by an extension.
323324

324325
An _explicitly resolved invocation_ of a constructor named `C.name` in a
325-
extension declaration _D_ named `E` with `s` type parameters and on-class
326-
`C` can be expressed as `E<S1 .. Ss>.C.name(args)`,
326+
extension declaration _D_ named `E` with `s` type parameters and
327+
on-declaration `C` can be expressed as `E<S1 .. Ss>.C.name(args)`,
327328
`E.C<U1 .. Uk>.name(args)`, or `E<S1 .. Ss>.C<U1 .. Uk>.name(args)` (and
328329
similarly for a constructor named `C` using `E<S1 .. Ss>.C(args)`, etc).
329330

@@ -355,7 +356,7 @@ them to explicitly resolved ones.*
355356

356357
A constructor invocation of the form `C<T1 .. Tm>.name(args)` is partially
357358
resolved by looking up a constructor named `C.name` in the class `C` and in
358-
every accessible extension with on-class `C`. A compile-time error
359+
every accessible extension with on-declaration `C`. A compile-time error
359360
occurs if no such constructor is found. Similarly, an invocation of the
360361
form `C<T1 ... Tm>(args)` uses a lookup for constructors named `C`.
361362

@@ -367,14 +368,14 @@ Otherwise, the invocation is partially resolved to a set _M_ of candidate
367368
constructors and static members found in extensions. Each of the candidates
368369
_kj_ is vetted as follows:
369370

370-
If `m` is zero and `E` is an accessible extension with on-class `C`
371+
If `m` is zero and `E` is an accessible extension with on-declaration `C`
371372
that declares a static member whose basename is `name` then the invocation
372373
is a static member invocation *(which is specified in an earlier section)*.
373374

374375
Otherwise, assume that _kj_ is a constructor declared by an extension _D_
375-
named `E` with type parameters `X1 extends B1 .. Xs extends Bs`, on-class
376-
`C`, and on-type `C<S1 .. Sm>`. Find actual values `U1 .. Us` for
377-
`X1 .. Xs` satisfying the bounds `B1 .. Bs`, such that
376+
named `E` with type parameters `X1 extends B1 .. Xs extends Bs`,
377+
on-declaration `C`, and on-type `C<S1 .. Sm>`. Find actual values
378+
`U1 .. Us` for `X1 .. Xs` satisfying the bounds `B1 .. Bs`, such that
378379
`([U1/X1 .. Us/Xs]C<S1 .. Sm>) == C<T1 .. Tm>`. This may determine the
379380
value of some of the actual type arguments `U1 .. Us`, and others may be
380381
unconstrained (because they do not occur in `C<T1 .. Tm>`). Actual type
@@ -406,7 +407,8 @@ unconstrained actual type arguments are given as `_` and inferred later).
406407
The expression is then treated as described above.
407408

408409
Next, we construct a set _M_ containing all accessible extensions with
409-
on-class `C` that declare a constructor named `C.name` (respectively `C`).
410+
on-declaration `C` that declare a constructor named `C.name` (respectively
411+
`C`).
410412

411413
In the case where _M_ contains exactly one extension `E` that declares a
412414
constructor named `C.name` (or `C`), the invocation is treated as

0 commit comments

Comments
 (0)