Description
This issue was originally filed by [email protected]
TO REPRODUCE:
Try to create a new Arc: "var arc = new Arc.startingAt(Point.origin, 25.0, 0.0, 4.0);"
/// Immutable 2D cartesian point.
class Point2d {
final double x,y;
const Point2d(this.x, this.y);
const Point2d.polar(double radians, [double radius = 1.0, Point2d origin = Point2d.origin]) :
x = radius * Math.cos(radians) + origin.x,
y = radius * Math.sin(radians) + origin.y;
Point2d operator +(Point2d p) => new Point2d(x + p.x, y + p.y);
Point2d operator -(Point2d p) => new Point2d(x - p.x, y - p.y);
static final Point2d origin = const Point2d(0.0, 0.0);
}
/// Immutable planar arc.
class Arc {
final double radius, startRadians, endRadians;
final Point2d center;
Arc.startingAt(
Point2d startPosition,
this.radius,
this.startRadians,
this.endRadians) : center = startPosition - new Point2d.polar(startRadians, radius);
}
main() {
var arc = new Arc.startingAt(Point2d.origin, 25.0, 0.0, 4.0);
}
EXPECTED OUTPUT
Arc is instantiated; main() exits normally.
OBSERVED OUTPUT
In editor:
Cannot access an instance field in an initializer expression
At runtime:
Error: line 31 pos 48: illegal access to 'this'
PRODUCT / OS VERSION
Dart Editor build 7905. OS X 10.7.4
ADDITIONAL INFORMATION
I can't think of a reason to disallow access to an instance field when it appears in the parameter list using the "this.foo" sugar (especially since there is no other name that we can use to refer to it).
I can easily work around this by not using the "this.foo" sugar, but the sugar is sweet :-)