From 41cb2eb73d4523a10628bc95e8550ecb880e7214 Mon Sep 17 00:00:00 2001 From: Lexidor Digital <31805625+lexidor@users.noreply.github.com> Date: Thu, 31 Oct 2019 21:23:31 +0100 Subject: [PATCH] Support `disallow_array_literal` (#201) * Support `disallow_array_literal` * Update .hhconfig * Enable strict options that introduce test failures * Require HHVM 4.25 for HHI support of array_literal * Test on composer.json version of hhvm --- .hhconfig | 1 + .travis.yml | 2 +- composer.json | 2 +- src/core/ComposableElement.php | 4 ++-- src/core/XHP.php | 6 +++--- tests/AsyncTest.php | 6 +++--- tests/AttributesTest.php | 8 ++++---- tests/BasicsTest.php | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.hhconfig b/.hhconfig index e098c907..f08bc44b 100644 --- a/.hhconfig +++ b/.hhconfig @@ -8,3 +8,4 @@ enable_experimental_tc_features=shape_field_check,sealed_classes user_attributes= disable_static_local_variables = true disable_primitive_refinement=true +disallow_array_literal = true diff --git a/.travis.yml b/.travis.yml index aa30d5a2..7fb90f73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: required language: generic services: docker env: -- HHVM_VERSION=4.13-latest +- HHVM_VERSION=4.25-latest - HHVM_VERSION=latest - HHVM_VERSION=nightly install: diff --git a/composer.json b/composer.json index 880c6436..e9354abf 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/facebook/xhp-lib", "license": ["MIT"], "require": { - "hhvm": "^4.13.0", + "hhvm": "^4.25", "hhvm/type-assert": "^3.0" }, "require-dev": { diff --git a/src/core/ComposableElement.php b/src/core/ComposableElement.php index ebc174ae..b2406e6e 100644 --- a/src/core/ComposableElement.php +++ b/src/core/ComposableElement.php @@ -793,7 +793,7 @@ public function __getChildrenDeclaration(): string { * :span[%inline],pcdata */ final public function __getChildrenDescription(): string { - $desc = array(); + $desc = varray[]; foreach ($this->children as $child) { if ($child is :xhp) { $tmp = ':'.:xhp::class2element(get_class($child)); @@ -815,7 +815,7 @@ final public function categoryOf(string $c): bool { return true; } // XHP parses the category string - $c = str_replace(array(':', '-'), array('__', '_'), $c); + $c = str_replace(varray[':', '-'], varray['__', '_'], $c); return ($categories[$c] ?? null) !== null; } } diff --git a/src/core/XHP.php b/src/core/XHP.php index 9ac9e8d0..010abf60 100644 --- a/src/core/XHP.php +++ b/src/core/XHP.php @@ -104,13 +104,13 @@ final protected static function renderChild(XHPChild $child): string { } public static function element2class(string $element): string { - return 'xhp_'.str_replace(array(':', '-'), array('__', '_'), $element); + return 'xhp_'.str_replace(varray[':', '-'], varray['__', '_'], $element); } public static function class2element(string $class): string { return str_replace( - array('__', '_'), - array(':', '-'), + varray['__', '_'], + varray[':', '-'], preg_replace('#^xhp_#i', '', $class), ); } diff --git a/tests/AsyncTest.php b/tests/AsyncTest.php index 86334054..84122df4 100644 --- a/tests/AsyncTest.php +++ b/tests/AsyncTest.php @@ -89,8 +89,8 @@ public function testInstanceOfInterface(): void { expect($xhp)->toBeInstanceOf(XHPAwaitable::class); } - public function parallelizationContainersProvider(): array> { - return [[], []]; + public function parallelizationContainersProvider(): varray> { + return varray[varray[], varray[]]; } <> @@ -101,7 +101,7 @@ public function testParallelization(:x:element $container): void { $b = ; $c = ; - $container->replaceChildren([$b, $c]); + $container->replaceChildren(varray[$b, $c]); $tree = {$a}{$container}; expect($tree->toString())->toBeSame( diff --git a/tests/AttributesTest.php b/tests/AttributesTest.php index 6faa3aae..40dcef85 100644 --- a/tests/AttributesTest.php +++ b/tests/AttributesTest.php @@ -81,7 +81,7 @@ public function testValidTypes(): void { mystring="foo" mybool={true} myint={123} - myarray={[1, 2, 3]} + myarray={varray[1, 2, 3]} myobject={new stdClass()} myenum={'foo'} myfloat={1.23} @@ -179,7 +179,7 @@ public function testUnstringableObjectAsString(): void { public function testArrayAsString(): void { expect(() ==> { - $x = ; + $x = ; })->toThrow(XHPInvalidAttributeException::class); } @@ -215,7 +215,7 @@ public function testObjectAsInt(): void { public function testArrayAsInt(): void { expect(() ==> { - $x = ; + $x = ; })->toThrow(XHPInvalidAttributeException::class); } @@ -326,7 +326,7 @@ public function testIncompatibleObjectAsObject(): void { public function testPassingArrayAsVector(): void { expect(() ==> { - $x = ; + $x = ; })->toThrow(XHPInvalidAttributeException::class); } diff --git a/tests/BasicsTest.php b/tests/BasicsTest.php index dfe3d6d1..bc82ca45 100644 --- a/tests/BasicsTest.php +++ b/tests/BasicsTest.php @@ -70,6 +70,6 @@ public function testRendersPrimitive(): void { public function testJsonSerialize(): void { $xhp =
Hello world.
; - expect(json_encode([$xhp]))->toBeSame('["
Hello world.<\/div>"]'); + expect(json_encode(varray[$xhp]))->toBeSame('["
Hello world.<\/div>"]'); } }