Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Support disallow_array_literal (#201)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lexidor authored and jjergus committed Oct 31, 2019
1 parent bb524d7 commit 41cb2eb
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/core/ComposableElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/core/XHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/AsyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function testInstanceOfInterface(): void {
expect($xhp)->toBeInstanceOf(XHPAwaitable::class);
}

public function parallelizationContainersProvider(): array<array<:xhp>> {
return [[<test:xfrag-wrap />], [<test:async-xfrag-wrap />]];
public function parallelizationContainersProvider(): varray<varray<:xhp>> {
return varray[varray[<test:xfrag-wrap />], varray[<test:async-xfrag-wrap />]];
}

<<DataProvider('parallelizationContainersProvider')>>
Expand All @@ -101,7 +101,7 @@ public function testParallelization(:x:element $container): void {
$b = <async:par-test label="b" />;
$c = <async:par-test label="c" />;

$container->replaceChildren([$b, $c]);
$container->replaceChildren(varray[$b, $c]);

$tree = <async:test>{$a}{$container}</async:test>;
expect($tree->toString())->toBeSame(
Expand Down
8 changes: 4 additions & 4 deletions tests/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function testUnstringableObjectAsString(): void {

public function testArrayAsString(): void {
expect(() ==> {
$x = <test:attribute-types mystring={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ []} />;
$x = <test:attribute-types mystring={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ varray[]} />;
})->toThrow(XHPInvalidAttributeException::class);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function testObjectAsInt(): void {

public function testArrayAsInt(): void {
expect(() ==> {
$x = <test:attribute-types myint={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ []} />;
$x = <test:attribute-types myint={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ varray[]} />;
})->toThrow(XHPInvalidAttributeException::class);
}

Expand Down Expand Up @@ -326,7 +326,7 @@ public function testIncompatibleObjectAsObject(): void {

public function testPassingArrayAsVector(): void {
expect(() ==> {
$x = <test:attribute-types myvector={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ [1, 2, 3]} />;
$x = <test:attribute-types myvector={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ varray[1, 2, 3]} />;
})->toThrow(XHPInvalidAttributeException::class);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/BasicsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function testRendersPrimitive(): void {

public function testJsonSerialize(): void {
$xhp = <div>Hello world.</div>;
expect(json_encode([$xhp]))->toBeSame('["<div>Hello world.<\/div>"]');
expect(json_encode(varray[$xhp]))->toBeSame('["<div>Hello world.<\/div>"]');
}
}

0 comments on commit 41cb2eb

Please sign in to comment.