-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
If you compile the following example in advanced mode, Child1#method123 is not removed, even though it is never used. The reason is that the compiler doesn't know that x in x.method123(0) can only ever be a Child2. It would be nice if we can do some simple flow analysis (eg, 0CFA) to catch things like that and remove more dead code.
/** @interface */
function Parent() {}
/** @return {number} */
Parent.prototype.method123 = function(x) {};
/** @constructor @implements {Parent} */
function Child1() { this.prop = 123; }
/** @override */
Child1.prototype.method123 = function(x) { return x+1; };
/** @constructor @implements {Parent} */
function Child2() {}
/** @override */
Child2.prototype.method123 = function(x) { return x-1; };
/** @param {!Parent} x */
function f(x) {
alert(x.method123(0));
}
alert((new Child1).prop);
f(new Child2);Reactions are currently unavailable