Chromium Code Reviews
DescriptionAllow optional initializing formals again
After removing optional initializing formal parameters from the VM
yesterday, the language team decided that they should be allowed
and made usable.
- The name of an optional initializing formal is the name of
the field it initializes.
- The parameter is only visible at the call site of the constructor,
to name the parameter.
- The parameter is NOT visible in the constructor's initializer list
and body.
class A {
A([this.x = 10]);
A.bad([this.x = 10]) : y = x; // Error: parameter x not in scope
A.ok([this.x = 10]) { print(x); } // Refers to field x, not parameter x.
var x, y;
}
o = new A(x: 50); // o.x == 50.
o = new A(); // o.x == 10.
Committed: https://code.google.com/p/dart/source/detail?r=1819
Patch Set 1 #Patch Set 2 : '' #Patch Set 3 : '' #Patch Set 4 : '' #
Messages
Total messages: 2 (0 generated)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||