google / google/closure-compiler

RemoveSuperMethodsPass makes an unsafe assumption

Open
#2,749 0 comments 0 reactions 1 assignee Claimed by @Dominator008 View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

RemoveSuperMethodsPass tries to remove methods that are just pass-through calls to a super class method.

e.g.
class A {
foo(a, b) { .. do something here ..}
}

class B extends A {
foo(a, b) { super.foo(a, b); } // remove this
}

These usually exist in order to tweak the return type of the child class method.

The trouble is that the pass makes the assumption that the parent and child class methods have the same number and order of arguments without actually checking this.

class A {
foo(a, b) { .. do something here ..}
}

class B extends A {
foo(a) { super.foo(a); } // this gets removed incorrectly
}

// Should end up calling A.prototype.foo.call(this, 1),
// but removal causes call to A.prototype.foo.call(this, 1, 2).
new B().foo(1, 2);

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.