@@ -142,27 +142,6 @@ class A(final int a);
142
142
class B(super.a) extends A;
143
143
```
144
144
145
- It could be argued that primary constructors should support arbitrary
146
- superinvocations using the specified superclass:
147
-
148
- ``` dart
149
- class B extends A { // OK.
150
- B(int a): super(a);
151
- }
152
-
153
- class B(int a) extends A(a); // Could be supported, but isn't!
154
- ```
155
-
156
- This is not supported for several reasons. First, primary constructors
157
- should be small and easy to read. Next, it is not obvious how the
158
- superconstructor arguments would fit into a mixin application (e.g., when
159
- the superclass is ` A with M1, M2 ` ), or how readable it would be if the
160
- superconstructor is named (` class B(int a) extends A.name(a); ` ). For
161
- instance, would it be obvious to all readers that the superclass is ` A ` and
162
- not ` A.name ` , and that all other constructors than the primary constructor
163
- will ignore the implied superinitialization ` super.name(a) ` and do their
164
- own thing (which might be implicit).
165
-
166
145
Next, the constructor can be named, and it can be constant:
167
146
168
147
``` dart
@@ -428,6 +407,31 @@ Finally, _k_ is added to _D2_.
428
407
429
408
### Discussion
430
409
410
+ It could be argued that primary constructors should support arbitrary
411
+ superinvocations using the specified superclass:
412
+
413
+ ``` dart
414
+ class B extends A { // OK.
415
+ B(int a): super(a);
416
+ }
417
+
418
+ class B(int a) extends A(a); // Could be supported, but isn't!
419
+ ```
420
+
421
+ There are several reasons why this is not supported. First, primary constructors
422
+ should be small and easy to read. Next, it is not obvious how the
423
+ superconstructor arguments would fit into a mixin application (e.g., when the
424
+ superclass is ` A with M1, M2 ` ), or how readable it would be if the
425
+ superconstructor is named (` class B(int a) extends A.name(a); ` ). For instance,
426
+ would it be obvious to all readers that the superclass is ` A ` and not ` A.name ` ,
427
+ and that all other constructors than the primary constructor will ignore the
428
+ implied superinitialization ` super.name(a) ` and do their own thing (which might
429
+ be implicit).
430
+
431
+ In short, if you need to write a complex superinitialization like
432
+ ` super.name(e1, otherName: e2) ` then you need to use a normal (non-primary)
433
+ constructor.
434
+
431
435
There was a [ proposal from Bob] [ ] that the primary constructor should be
432
436
expressed at the end of the class header, in order to avoid readability
433
437
issues in the case where the superinterfaces contain a lot of text. It
0 commit comments