Page MenuHomePhabricator

XHPASTLinter does not scope parameters to closures correctly
Open, WishlistPublic

Description

lintUndeclaredVariables in XHPASTLinter will currently raise issues on most closures used within methods/functions.
E.g.:

function test() {
  $x = function($y) {
    return $y + 1;
  };
}

or

function test() {
  array_map(function($y) { return $y + 1; }, array(1, 2));
}

will state $y as undeclared in the surrounding function test() for both cases.
The closures itself will be linted correctly but the closure parameter will be treated like a variable in the surrounding function.

There already is a TODO comment in the linter function in question but i did not find a corresponding task for it.:

// TODO: Support functions defined inside other functions which is commonly
// used with anonymous functions.

Unfortunately this seems to be a bit tricky to implement properly as it will probably change the whole way the linter function currently works but maybe someone has a quick fix (just ignoring these functions/function parameters?)

Event Timeline

fabe raised the priority of this task from to Needs Triage.
fabe updated the task description. (Show Details)
fabe added projects: Lint, XHPAST.
fabe added a subscriber: fabe.
epriestley renamed this task from Treat functions with parameters defined in other functions in XHPASTLinter correctly to XHPASTLinter does not scope parameters to closures correctly.Apr 7 2020, 1:31 PM
epriestley triaged this task as Wishlist priority.