From 8c6e1284cc656034955228412154b22b556b5430 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 18 May 2015 09:04:22 +1000 Subject: [PATCH] Improve ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION Summary: The `ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION` linter rule was introduced in D12854, but fails for the following: - Interfaces which declare the `__toString()` method. - Classes which mark the `__toString()` method as `abstract`. Test Plan: Added test cases. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12892 --- src/lint/linter/ArcanistXHPASTLinter.php | 10 +++++++--- .../__tests__/xhpast/tostring-exception.lint-test | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index cad5bffa..88e4ffea 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -4144,9 +4144,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { continue; } - $throws = $method - ->getChildOfType(5, 'n_STATEMENT_LIST') - ->selectDescendantsOfType('n_THROW'); + $statements = $method->getChildByIndex(5); + + if ($statements->getTypeName() != 'n_STATEMENT_LIST') { + continue; + } + + $throws = $statements->selectDescendantsOfType('n_THROW'); foreach ($throws as $throw) { $this->raiseLintAtNode( diff --git a/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test b/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test index 2788fbdc..32913db7 100644 --- a/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test +++ b/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test @@ -14,5 +14,13 @@ class MyOtherClass { return 'Success'; } } + +interface SomeInterface { + public function __toString(); +} + +abstract class SomeAbstractClass { + abstract public function __toString(); +} ~~~~~~~~~~ error:5:7 -- 2.43.0