From: Joshua Spence Date: Wed, 2 Dec 2015 21:30:29 +0000 (+1100) Subject: Add binary integers to `ArcanistPHPCompatibilityXHPASTLinterRule` X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ae3c2cb0e17296ed29ef9d09d02a9f5c0daa6791;p=arcanist.git Add binary integers to `ArcanistPHPCompatibilityXHPASTLinterRule` Summary: Binary integers (such as `0b1`) were added to PHP 5.4 and cannot be used in earlier versions. Test Plan: Added a test case. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14643 --- diff --git a/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php index b91fc560..e9f4ab71 100644 --- a/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php @@ -414,6 +414,16 @@ final class ArcanistPHPCompatibilityXHPASTLinterRule '$this')); } } + + $numeric_scalars = $root->selectDescendantsOfType('n_NUMERIC_SCALAR'); + foreach ($numeric_scalars as $numeric_scalar) { + if (preg_match('/^0b[01]+$/i', $numeric_scalar->getConcreteString())) { + $this->raiseLintAtNode( + $numeric_scalar, + pht( + 'Binary integer literals are not available before PHP 5.4.')); + } + } } private function lintPHP54Incompatibilities(XHPASTNode $root) { diff --git a/src/lint/linter/xhpast/rules/__tests__/php-compatibility/php54-features.lint-test b/src/lint/linter/xhpast/rules/__tests__/php-compatibility/php54-features.lint-test index 99bb6dd7..4fb4e6c0 100644 --- a/src/lint/linter/xhpast/rules/__tests__/php-compatibility/php54-features.lint-test +++ b/src/lint/linter/xhpast/rules/__tests__/php-compatibility/php54-features.lint-test @@ -20,11 +20,14 @@ final class SomeClass extends Phobject { } } +0b1; + ~~~~~~~~~~ error:3:5 error:4:9 error:12:7 error:18:7 +error:23:1 ~~~~~~~~~~ ~~~~~~~~~~ {