Skip to content

Commit cc3cc2e

Browse files
committed
Work in progress
1 parent 462d7fa commit cc3cc2e

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SortedList<X> {
105105
}
106106
107107
static extension<X extends Comparable<X>> on SortedList<X> {
108-
SortedList.ofComparable(): super((X a, X b) => a.compareTo(b));
108+
SortedList.ofComparable(): this((X a, X b) => a.compareTo(b));
109109
}
110110
```
111111

@@ -174,12 +174,15 @@ The grammar is modified as follows:
174174

175175
In a static extension of the form `static extension E on C {...}` where `C`
176176
is an identifier or an identifier with an import prefix, we say that the
177-
on-class of the static extension is `C`. If `C` resolves to a non-generic
178-
class then we say that the _constructor return type_ of the static
179-
extension is `C`.
177+
on-class of the static extension is `C`.
180178

181-
*If `C` resolves to a generic class then the static extension does not have
182-
a constructor return type.*
179+
If `C` denotes a non-generic class, mixin, mixin class, or extension
180+
type then we say that the _constructor return type_ of the static extension
181+
is `C`.
182+
183+
If `C` denotes a generic class then `E` is treated as
184+
`static extensionE on C<T1 .. Tk> {...}`
185+
where `T1 .. Tk` are obtained by instantiation to bound.
183186

184187
In a static extension of the form `static extension E on C<T1 .. Tk> {...}`
185188
where `C` is an identifier or prefixed identifier, we say that the on-class
@@ -247,8 +250,8 @@ Tools may report diagnostic messages like warnings or lints in certain
247250
situations. This is not part of the specification, but here is one
248251
recommended message:
249252

250-
A compile-time message is emitted if a static extension _D_ declares a
251-
constructor or a static member with the same name as a constructor or a
253+
A compile-time diagnostic is emitted if a static extension _D_ declares a
254+
constructor or a static member with the same basename as a constructor or a
252255
static member in the on-class of _D_.
253256

254257
*In other words, a static extension should not have name clashes with its
@@ -309,11 +312,11 @@ on-class `C` and a member named `m`.
309312

310313
If `C` contains such a declaration then the expression is an invocation of
311314
that static member of `C`, with the same static analysis and dynamic
312-
behavior as before the introduction of this feature.
315+
semantics as before the introduction of this feature.
313316

314-
Otherwise, an error occurs if fewer than one or more than one declaration
315-
named `m` was found. *They would necessarily be declared in static
316-
extensions.*
317+
Otherwise, an error occurs if no declarations named `m` or more than one
318+
declaration named `m` were found. *They would necessarily be declared in
319+
static extensions.*
317320

318321
Otherwise, the invocation is resolved to the given static member
319322
declaration in a static extension named `Ej`, and the invocation is treated
@@ -327,9 +330,9 @@ parameters `X1 extends B1 .. Xs extends Bs` and an actual type argument
327330
list `T1 .. Ts` with a type known as the _instantiated constructor return
328331
type of_ _D_ _with type arguments_ `T1 .. Ts`.
329332

330-
When a static extension declaration _D_ named `E` has an on-clause which is
331-
a non-generic class `C`, the instantiated constructor return type is `C`,
332-
for any list of actual type arguments.
333+
When a static extension declaration _D_ named `E` has an on-clause which
334+
denotes a non-generic class `C`, the instantiated constructor return type
335+
is `C`, for any list of actual type arguments.
333336

334337
*It is not very useful to declare a type parameter of a static extension
335338
which isn't used in the constructor return type, because it can only be
@@ -417,13 +420,13 @@ henceforth treated as `E<U1 .. Us>.C<T1 .. Tm>.name(args)` (respectively
417420
`E<U1 .. Us>.C<T1 .. Tm>(args)`).
418421

419422
A constructor invocation of the form `C.name(args)` (respectively
420-
`C(args)`) where `C` resolves to a non-generic class is resolved in the
423+
`C(args)`) where `C` denotes a non-generic class is resolved in the
421424
same manner, with `m == 0`. *In this case, type parameters declared by `E`
422425
will be bound to values selected by instantiation to bound.*
423426

424427
Consider a constructor invocation of the form `C.name(args)` (and similarly
425-
for `C(args)`) where `C` resolves to a generic class. As usual, the
426-
invocation is treated as in the pre-feature language when it resolves to a
428+
for `C(args)`) where `C` denotes a generic class. As usual, the
429+
invocation is treated as in the pre-feature language when it denotes a
427430
constructor declared by the class `C`.
428431

429432
In the case where the context type schema for this invocation fully

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SortedList<X> {
9696
}
9797
9898
extension<X extends Comparable<X>> on SortedList<X> {
99-
SortedList.ofComparable(): super((X a, X b) => a.compareTo(b));
99+
SortedList.ofComparable(): this((X a, X b) => a.compareTo(b));
100100
}
101101
```
102102

@@ -132,20 +132,23 @@ usual, e.g., if a redirecting factory constructor redirects to a
132132
constructor that does not exist, or there is a redirection cycle.*
133133

134134
In an extension declaration of the form `extension E on C {...}` where `C`
135-
is an identifier or an identifier with an import prefix that resolves to a
135+
is an identifier or an identifier with an import prefix that denotes a
136136
class, mixin, enum, or extension type declaration, we say that the
137-
_on-class_ of the extension is `C`. If `C` resolves to a non-generic class
138-
then we say that the _constructor return type_ of the extension is `C`.
137+
_on-class_ of the extension is `C`. If `C` denotes a non-generic class,
138+
mixin, mixin class, or extension type then we say that the _constructor return
139+
type_ of the extension is `C`.
139140

140-
*If `C` resolves to a generic class then the extension does not have a
141-
constructor return type.*
141+
If `C` denotes a generic class then `E` is treated as
142+
`extension E on C<T1 .. Tk> {...}` where `T1 .. Tk` are obtained by
143+
instantiation to bound.
142144

143-
In a extension of the form `extension E on C<T1 .. Tk> {...}`
144-
where `C` is an identifier or prefixed identifier that resolves to a class,
145+
In an extension of the form `extension E on C<T1 .. Tk> {...}`
146+
where `C` is an identifier or prefixed identifier that denotes a class,
145147
mixin, enum, or extension type declaration, we say that the _on-class_
146148
of `E` is `C`, and the _constructor return type_ of `E` is `C<T1 .. Tk>`.
147149

148-
In all other cases, an extension declaration does not have an on-class.
150+
In all other cases, an extension declaration does not have an on-class nor a
151+
constructor return type.
149152

150153
*For example, an extension whose on-type is a type variable does not have
151154
an on-class, and neither does an extension whose on-type is a function
@@ -165,8 +168,8 @@ Tools may report diagnostic messages like warnings or lints in certain
165168
situations. This is not part of the specification, but here is one
166169
recommended message:
167170

168-
A compile-time message is emitted if a extension _D_ declares a
169-
constructor or a static member with the same name as a constructor or a
171+
A compile-time diagnostic is emitted if an extension _D_ declares a
172+
constructor or a static member with the same basename as a constructor or a
170173
static member in the on-class of _D_.
171174

172175
*In other words, an extension should not have name clashes with its
@@ -194,10 +197,11 @@ on-class `C` and a static member named `m`.
194197

195198
If `C` contains such a declaration then the expression is an invocation of
196199
that static member of `C`, with the same static analysis and dynamic
197-
behavior as before the introduction of this feature.
200+
semantics as before the introduction of this feature.
198201

199-
Otherwise, an error occurs if fewer than one or more than one declaration
200-
named `m` was found. *They would necessarily be declared in extensions.*
202+
Otherwise, an error occurs if no declarations named `m` or more than one
203+
declaration named `m` were found. *They would necessarily be declared in
204+
extensions.*
201205

202206
Otherwise, the invocation is resolved to the given static member
203207
declaration in an extension named `Ej`, and the invocation is treated
@@ -211,7 +215,7 @@ parameters `X1 extends B1 .. Xs extends Bs` and an actual type argument
211215
list `T1 .. Ts` with a type known as the _instantiated constructor return
212216
type of_ _D_ _with type arguments_ `T1 .. Ts`.
213217

214-
When an extension declaration _D_ named `E` has an on-clause which is
218+
When an extension declaration _D_ named `E` has an on-clause which denotes
215219
a non-generic class `C`, the instantiated constructor return type is `C`,
216220
for any list of actual type arguments.
217221

@@ -221,7 +225,7 @@ passed in an explicitly resolved constructor invocation, e.g.,
221225
`E<int>.C(42)`. In all other invocations, the value of such type variables
222226
is determined by instantiation to bound. In any case, the type parameters
223227
are always ignored by static member declarations, they are only relevant to
224-
constructors.*
228+
constructors and instance members.*
225229

226230
When an extension declaration _D_ has no formal type parameters, and
227231
it has an on-type `C<S1 .. Sk>`, the instantiated constructor return type
@@ -287,7 +291,7 @@ Otherwise, the invocation is partially resolved to a set of candidate
287291
constructors found in extensions. Each of the candidates _kj_ is
288292
vetted as follows:
289293

290-
Assume that _kj_ is a constructor declared by a extension _D_ named
294+
Assume that _kj_ is a constructor declared by an extension _D_ named
291295
`E` with type parameters `X1 extends B1 .. Xs extends Bs` and on-type
292296
`C<S1 .. Sm>`. Find actual values `U1 .. Us` for `X1 .. Xs` satisfying the
293297
bounds `B1 .. Bs`, such that `([U1/X1 .. Us/Xs]C<S1 .. Sm>) == C<T1 .. Tm>`.
@@ -300,13 +304,13 @@ henceforth treated as `E<U1 .. Us>.C<T1 .. Tm>.name(args)` (respectively
300304
`E<U1 .. Us>.C<T1 .. Tm>(args)`).
301305

302306
A constructor invocation of the form `C.name(args)` (respectively
303-
`C(args)`) where `C` resolves to a non-generic class is resolved in the
307+
`C(args)`) where `C` denotes a non-generic class is resolved in the
304308
same manner, with `m == 0`. *In this case, type parameters declared by `E`
305309
will be bound to values selected by instantiation to bound.*
306310

307311
Consider a constructor invocation of the form `C.name(args)` (and similarly
308-
for `C(args)`) where `C` resolves to a generic class. As usual, the
309-
invocation is treated as in the pre-feature language when it resolves to a
312+
for `C(args)`) where `C` denotes a generic class. As usual, the
313+
invocation is treated as in the pre-feature language when it denotes a
310314
constructor declared by the class `C`.
311315

312316
In the case where the context type schema for this invocation fully
@@ -315,7 +319,7 @@ receive said actual type arguments, `C<T1 .. Tm>.name(args)`, and treated
315319
as described above.
316320

317321
In the case where the invocation resolves to exactly one constructor
318-
`C.name` (or `C`) declared by a extension named `E`, the invocation
322+
`C.name` (or `C`) declared by an extension named `E`, the invocation
319323
is treated as `E.C.name(args)` (respectively `E.C(args)`).
320324

321325
Otherwise, when there are two or more candidates from extensions,

0 commit comments

Comments
 (0)