Summary:
Currently, when code has a block like:
} catch (Exception $ex) {
...we attempt to mark "$ex" as declared. However, we incorrectly mark every variable used anywhere in the block as declared. This means we'll never raise this warning in a `catch` block.
Instead //only// mark the caught exception as declared.
Test Plan: Added a failing unit test and made it pass.
Reviewers: joshuaspence, btrahan
Reviewed By: btrahan
Subscribers: lpriestley, epriestley
Differential Revision: https://secure.phabricator.com/D9239
}
}
- $catches = $body
- ->selectDescendantsOfType('n_CATCH')
- ->selectDescendantsOfType('n_VARIABLE');
- foreach ($catches as $var) {
- $vars[] = $var;
+ // Include "catch (Exception $ex)", but not variables in the body of the
+ // catch block.
+ $catches = $body->selectDescendantsOfType('n_CATCH');
+ foreach ($catches as $catch) {
+ $vars[] = $catch->getChildOfType(1, 'n_VARIABLE');
}
$binary = $body->selectDescendantsOfType('n_BINARY_EXPRESSION');
echo "$b";
}
+function catchy() {
+ try {
+ dangerous();
+ } catch (Exception $ex) {
+ $y->z();
+ }
+}
+
~~~~~~~~~~
disabled:3:1
error:30:3
error:146:8
error:152:9
error:166:9
+error:173:5