]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add binary integers to `ArcanistPHPCompatibilityXHPASTLinterRule`
authorJoshua Spence <josh@freelancer.com>
Wed, 2 Dec 2015 21:30:29 +0000 (08:30 +1100)
committerJoshua Spence <josh@freelancer.com>
Wed, 2 Dec 2015 21:39:11 +0000 (08:39 +1100)
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

src/lint/linter/xhpast/rules/ArcanistPHPCompatibilityXHPASTLinterRule.php
src/lint/linter/xhpast/rules/__tests__/php-compatibility/php54-features.lint-test

index b91fc560d8366b02610a2a25bf778f8f668a0858..e9f4ab7141b39343f5be562f231a109d53b896c0 100644 (file)
@@ -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) {
index 99bb6dd7711b1243603f29eac838e8ff39387694..4fb4e6c07d26a1f9769e6e1f9602c94244df4ab3 100644 (file)
@@ -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
 ~~~~~~~~~~
 ~~~~~~~~~~
 {