From ae3c2cb0e17296ed29ef9d09d02a9f5c0daa6791 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 3 Dec 2015 08:30:29 +1100 Subject: [PATCH] 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 --- .../rules/ArcanistPHPCompatibilityXHPASTLinterRule.php | 10 ++++++++++ .../php-compatibility/php54-features.lint-test | 3 +++ 2 files changed, 13 insertions(+) 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 ~~~~~~~~~~ ~~~~~~~~~~ { -- 2.43.0