From: Joshua Spence Date: Sun, 17 May 2015 21:47:19 +0000 (+1000) Subject: Improve the "invalid parent scope" linter rule X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1df248cc2d53ecfc0dae1e2ae58b4e56f7a4acdc;p=arcanist.git Improve the "invalid parent scope" linter rule Summary: This linter rule was introduced in D12420, but fails to handle a specific edge case. Test Plan: Added test case. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12853 --- diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 380cbd8c..5f08f150 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -3872,7 +3872,11 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { ->selectDescendantsOfType('n_CLASS_STATIC_ACCESS'); foreach ($static_accesses as $static_access) { - $called_class = $static_access->getChildOfType(0, 'n_CLASS_NAME'); + $called_class = $static_access->getChildByIndex(0); + + if ($called_class->getTypeName() != 'n_CLASS_NAME') { + continue; + } if ($called_class->getConcreteString() == 'parent') { $this->raiseLintAtNode( diff --git a/src/lint/linter/__tests__/xhpast/no-parent-scope.lint-test b/src/lint/linter/__tests__/xhpast/no-parent-scope.lint-test index 5251ea96..b9389611 100644 --- a/src/lint/linter/__tests__/xhpast/no-parent-scope.lint-test +++ b/src/lint/linter/__tests__/xhpast/no-parent-scope.lint-test @@ -10,6 +10,10 @@ final class MyInvalidClass { public function __construct() { parent::__construct(null); } + + public function someMethod($x) { + echo $x::SOME_CONSTANT; + } } ~~~~~~~~~~ error:11:5