Open
Description
In the following code:
class Super {
void error() {
throw "super error";
}
}
class Sub extends Super {
void error() {
throw "sub error";
}
}
main() async {
new Sub().error();
}
Super.error()
is unreachable, but dart2js (as of 0c005a3) fails to tree-shake it:
$ dart2js test.dart
$ grep -n "super error" out.js
4936: throw H.wrapException("super error");
This seems to be dependent on the name of the method. If I change it to error_()
:
class Super {
void error_() {
throw "super error";
}
}
class Sub extends Super {
void error_() {
throw "sub error";
}
}
main() async {
new Sub().error_();
}
Super.error_()
does seem to be tree-shaken:
$ dart2js test.dart
$ grep -n "super error" out.js
4936: throw H.wrapException("super error");
This came up in practice when trying to reduce the code size of the http
package and its dependencies.