Open DartBot opened 12 years ago
This comment was originally written by sc...@gmail.com
Oops, I misread the spec. There is no bug. Foo should be defined as:
class Foo { var a,b; Foo(this.a, this.b); Foo.yo(var aa, var bb) { a = aa; b = bb; print("yo!!"); } // Both of these result in static errors. Foo.redirect1(var aa, var bb) : this(aa, bb); Foo.redirect2(var aa, var bb) : this.yo(aa, bb); }
dart2js produce these error messages:
fisk.dart:8:34: error: cannot resolve constructor Foo.Foo Foo.redirect1(var aa, var bb) : this.Foo(aa, bb); ^^^^^^^^^^^^^^^^ Error: Compilation failed.
fisk.dart:9:34: error: only call to 'this' or 'super' constructor allowed Foo.redirect2(var aa, var bb) : this.Foo.yo(aa, bb); ^^^^^^^^^^^^^^^^^^^ Error: Compilation failed.
Are these messages good enough?
This comment was originally written by sch...@gmail.com
The messages were unhelpful; to resolve my problem I had to resort to web-search. My responses to the two messages:
"Cannot resolve". "Why not?"
"Can only call 'this' or 'super' constructor" "I thought that's what I was doing"
Ideally, the message would ask "did you mean 'this.yo(aa, bb)'? "
BTW, as others have said on the list, it's very laudable that you're taking such an interest in the developer UX. Thank you! It will be difficult to quantify the benefits, but in the long term it will make the web a much nicer platform.
This comment was originally written by sc...@gmail.com
Clarification... along with the current messages, it would be great if the compiler additionally asked "did you mean..." in these cases.
I'm reopening this to track improving the error message.
Removed Type-Defect, Priority-Medium labels. Added Type-Enhancement, Priority-Low, Area-Dart2JS, Triaged labels.
Changed the title to: "Improve error message for redirecting constructors".
Added this to the M2 milestone. Removed Priority-Low label. Added Priority-Medium label.
Removed Type-Enhancement label. Added Type-Defect label.
Removed Priority-Medium label. Added Priority-Low label.
Removed this from the M2 milestone. Added this to the Later milestone. Removed Priority-Low label. Added Priority-Medium label.
Added TriageForM5 label.
Removed TriageForM5 label.
Removed this from the Later milestone. Added Oldschool-Milestone-Later label.
Removed Oldschool-Milestone-Later label.
Today dart2js successfully compiles both the original script in this issue, and the script in #1, without any warnings or errors. This can be closed.
The messages still need improvement.
The current response has improved slightly:
issue3265.dart:12:35: Error: Expected an assignment after the field name.
To initialize a field, use the syntax 'name = value'.
Foo.redirect2(var aa, var bb) : this.Foo.yo(aa, bb);
^^^^
issue3265.dart:11:35: Error: Couldn't find constructor 'Foo.Foo'.
Foo.redirect1(var aa, var bb) : this.Foo(aa, bb);
^^^^
issue3265.dart:12:35: Error: Can't access 'this' in a field initializer.
Foo.redirect2(var aa, var bb) : this.Foo.yo(aa, bb);
^^^^
This issue was originally filed by schwa...@gmail.com
REPRODUCING STEPS
class Foo { var a,b; Foo(this.a, this.b); Foo.yo(var aa, var bb) { a = aa; b = bb; print("yo!!"); } // Both of these result in static errors. Foo.redirect1(var aa, var bb) : this.Foo(aa, bb); Foo.redirect2(var aa, var bb) : this.Foo.yo(aa, bb); }
EXPECTED / OBSERVED OUTPUT I don't expect any static errors in this code.
DART / OS VERSIONS Dart Editor build 7905, OS X 10.7.4