@@ -4,7 +4,7 @@ Author: Bob Nystrom
4
4
5
5
Status: In-progress
6
6
7
- Version 1.4
7
+ Version 1.5
8
8
9
9
## Motivation
10
10
@@ -317,37 +317,45 @@ class C {
317
317
318
318
### Super parameters
319
319
320
- An occurrence of ` super._ ` as a declaration of a formal parameter in a
321
- constructor is a compile-time error. This error also occurs in the case
322
- where the super parameter has an explicitly declared type and/or default
323
- value.
324
-
325
- * ` super._ ` is not an error everywhere: In a method body it could be an
326
- invocation of an inherited getter named ` _ ` .*
320
+ The positional formal parameter ` super._ ` is still allowed in non-redirecting
321
+ generative constructors. Such a parameter forwards the argument's value to the
322
+ super constructor invocation.
327
323
328
324
``` dart
329
- class B {
330
- final _ ;
331
- B (this._ );
325
+ class A {
326
+ final int x, y ;
327
+ A (this.x, this.y );
332
328
}
333
329
334
- class C extends B {
335
- C(super._); // Error.
330
+ class B extends A {
331
+ final int _;
332
+ B(this._, super._, super._) { // No collision on multiple `super._`.
333
+ print(_ + x + y); // Refers to `B._`, `A.x` and `A.y`.
334
+ }
336
335
}
337
336
```
338
337
339
- * The desugared meaning of a super parameter includes a reference to the
340
- parameter in the initializer list of the enclosing constructor declaration,
341
- but such references are not possible when the parameter name is a
342
- wildcard.*
338
+ Similarly to ` this._ ` , and unlike for example ` super.x ` , a ` super._ ` does not
339
+ introduce any identifier into the scope of the initializer list.
340
+
341
+ Because of that, multiple ` super._ ` and ` this._ ` parameters can occur in the
342
+ same constructor without any name collision.
343
+
344
+ ``` dart
345
+ class A {
346
+ final int _, v;
347
+ A(this._, this.v);
348
+ }
343
349
344
- * It may seem inconvenient that ` super._ ` "does not work" in the last
345
- example, but we do not wish to create exceptions about the ability to refer
346
- to a declaration whose name is a wildcard, just so we can support this
347
- particular usage. The advice would be to use a different name than ` _ ` for
348
- the instance variable in ` B ` in the first place, or using a different name
349
- in ` B ` and possibly ` // ignore ` a lint that may warn about the names being
350
- different.*
350
+ class B extends A {
351
+ B(super.x, super._)
352
+ : assert(x > 0), // OK, `x` in scope.
353
+ assert(_ >= 0) // Error: no `_` in scope.
354
+ {
355
+ print(_); // OK, means `this._` and refers to `A._`.
356
+ }
357
+ }
358
+ ```
351
359
352
360
### Extension types
353
361
@@ -461,6 +469,9 @@ This lint is included in the core lint set which means that the scale of the bre
461
469
462
470
## Changelog
463
471
472
+ ### 1.5
473
+ - Allow ` super._ ` . Discussion: [ language/#3792 ] ( https://github.com/dart-lang/language/issues/3792 )
474
+
464
475
### 1.4
465
476
- Add section on import prefixes. Discussion: [ language/#3799 ] ( https://github.com/dart-lang/language/issues/3799 )
466
477
0 commit comments