Skip to content
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

Incorrect override functions with optional parameter #2122

Closed
ikabirov opened this issue Nov 2, 2016 · 3 comments
Closed

Incorrect override functions with optional parameter #2122

ikabirov opened this issue Nov 2, 2016 · 3 comments
Assignees
Labels

Comments

@ikabirov
Copy link
Contributor

ikabirov commented Nov 2, 2016

When using ADVANCED_OPTIMIZATIONS option, the compiler ignores overriden functions that just call base class method without passing optional arguments:

/**
 * @param {number=} width
 * @param {number=} height
 */
Foo.prototype.resize = function(width, height) {}

it is ok when undefined height is passed explicitly

/** @inheritDoc */
Bar.prototype.resize = function(width, height) {
    goog.base(this, "resize", width, undefined);
};

However, if height is not passed, the compiler throws away Bar.prototype.resize method completely

/** @inheritDoc */
Bar2.prototype.resize = function(width, height) {
    goog.base(this, "resize", width);
};

this bar will be removed from output code

    bar.resize(100, 200);
    console.log(bar.width(), bar.height()); // 100 undefined
 
    bar2.resize(100, 200);
    console.log(bar2.width(), bar2.height()); // 100 200

Minimal code to reproduce this issue: main.txt

@Dominator008
Copy link
Contributor

Dominator008 commented Nov 2, 2016

Looks like a too aggressive optimization to me, but your code is actually confusing :)

Can you try changing the goog.base to Bar.base following https://github.com/google/closure-library/wiki/How-to-migrate-from-goog.base?

Not sure if that's a workaround while we investigate the problem.

@Dominator008 Dominator008 self-assigned this Nov 2, 2016
@MatrixFrog
Copy link
Contributor

I think there was an optimization added recently that removes overrides that do nothing but call the base method. Sometimes you need these so you can add more specific type annotations, but at runtime there's no value in keeping them. I'll see if I can find it.

@blickly blickly closed this as completed in 58e612c Nov 3, 2016
alexeykomov pushed a commit to alexeykomov/closure-compiler that referenced this issue Feb 8, 2017
OptimizeCalls can change the number of parameters, which breaks the assumption
of RemoveSuperMethodsPass in some cases.

Fixes google#2122 on GitHub.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137999659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants