Skip to content

Tree-shaking unused superclass method named "error" fails #30962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nex3 opened this issue Oct 2, 2017 · 0 comments
Open

Tree-shaking unused superclass method named "error" fails #30962

nex3 opened this issue Oct 2, 2017 · 0 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@nex3
Copy link
Member

nex3 commented Oct 2, 2017

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.

@nex3 nex3 added web-dart2js type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 2, 2017
@nex3 nex3 changed the title Tree-shaking unused superclass methods sometimes fails Tree-shaking unused superclass method named "error" fails Oct 2, 2017
@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants