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

Extract local refactor creates incorrect code when expression depends on function literal parameter #18895

Closed
stereotype441 opened this issue May 19, 2014 · 7 comments

Comments

@stereotype441
Copy link
Member

Given this code:

  f(g) {
  }
  main() {
    f((x) => x.y + 1);
  }

Select "x.y" and perform an "extract local variable" refactor. This produces the following result:

  f(g) {
  }
  main() {
    var z = x.y;
    f((x) => z + 1);
  }

which is incorrect, since x previously referred to the argument of the function literal "(x) => x.y + 1"; now it is an undefined name.

IMHO, the correct result is:

  f(g) {
  }
  main() {
    f((x) {
      var z = x.y;
      return z + 1;
    });
  }

(that is, the function literal should be converted into block form so that the new variable declaration can go inside it).

@clayberg
Copy link

Set owner to @scheglov.
Added this to the 1.5 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@kasperl
Copy link

kasperl commented Jun 4, 2014

Removed this from the 1.5 milestone.
Added this to the 1.6 milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the 1.6 milestone.
Added Oldschool-Milestone-1.6 label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-1.6 label.

@sethladd
Copy link
Contributor

Removed Area-Editor label.
Added Area-Analyzer, Analyzer-Refactoring labels.

@scheglov
Copy link
Contributor

@scheglov
Copy link
Contributor

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants