Skip to content

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

Open
@nex3

Description

@nex3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions