Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 2b723b3

Browse files
lexidorjjergus
authored andcommitted
Support disallow_array_literal (#17)
* Support `disallow_array_literal` * Enable strict options that introduce test failures * Require HHVM 4.25 for HHI support of array_literal * Test on composer.json version of hhvm
1 parent e989589 commit 2b723b3

File tree

9 files changed

+30
-29
lines changed

9 files changed

+30
-29
lines changed

.hhconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ enable_experimental_tc_features=shape_field_check,sealed_classes
88
user_attributes=
99
disable_primitive_refinement=true
1010
disable_static_local_variables = true
11+
disallow_array_literal = true

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: required
22
language: generic
33
services: docker
44
env:
5-
- HHVM_VERSION=4.18-latest
5+
- HHVM_VERSION=4.25-latest
66
- HHVM_VERSION=latest
77
- HHVM_VERSION=nightly
88
install:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"keywords": ["hack", "router", "routing", "hhvm"],
66
"homepage": "https://github.com/hhvm/hack-router",
77
"require": {
8-
"hhvm": "^4.18",
8+
"hhvm": "^4.25",
99
"hhvm/hsl": "^4.0",
1010
"facebook/hack-http-request-response-interfaces": "^0.2"
1111
},

src/router/PrefixMatchingResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private function resolveWithMap(
6363
$regexps = $map->getRegexps();
6464
foreach ($regexps as $regexp => $_sub_map) {
6565
$pattern = '#^'.$regexp.'#';
66-
$matches = [];
66+
$matches = varray[];
6767

6868
if (\preg_match_with_matches($pattern, $path, inout $matches) !== 1) {
6969
continue;

src/router/SimpleRegexpResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function resolve(
3333
}
3434
$map = $this->map[$method];
3535
foreach ($map as $regexp => $responder) {
36-
$matches = [];
36+
$matches = varray[];
3737
if (\preg_match_with_matches($regexp, $path, inout $matches) !== 1) {
3838
continue;
3939
}

tests/ParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use type Facebook\HackTest\DataProvider;
1515

1616
final class ParserTest extends \Facebook\HackTest\HackTest {
17-
public function getExamplePatterns(): array<(string, string)> {
18-
return [
17+
public function getExamplePatterns(): varray<(string, string)> {
18+
return varray[
1919
tuple('/foo', "['/foo']"),
2020
tuple('/foo/{bar}', "['/foo/', {bar}]"),
2121
tuple('/foo/[{bar}]', "['/foo/', ?[{bar}]]"),

tests/RequestParametersTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@
1515

1616
final class RequestParametersTest extends \Facebook\HackTest\HackTest {
1717
public function testStringParam(): void {
18-
$parts = [new StringRequestParameter(
18+
$parts = varray[new StringRequestParameter(
1919
StringRequestParameterSlashes::WITHOUT_SLASHES,
2020
'foo',
2121
)];
2222
$data = dict['foo' => 'bar'];
23-
expect((new RequestParameters($parts, [], $data))->getString('foo'))
23+
expect((new RequestParameters($parts, varray[], $data))->getString('foo'))
2424
->toBeSame('bar');
2525
}
2626

2727
public function testIntParam(): void {
28-
$parts = [new IntRequestParameter('foo')];
28+
$parts = varray[new IntRequestParameter('foo')];
2929
$data = dict['foo' => '123'];
30-
expect((new RequestParameters($parts, [], $data))->getInt('foo'))->toBeSame(
30+
expect((new RequestParameters($parts, varray[], $data))->getInt('foo'))->toBeSame(
3131
123,
3232
);
3333
}
3434

3535
public function testFetchingStringAsInt(): void {
3636
expect(() ==> {
37-
$parts = [new StringRequestParameter(
37+
$parts = varray[new StringRequestParameter(
3838
StringRequestParameterSlashes::WITHOUT_SLASHES,
3939
'foo',
4040
)];
4141
$data = dict['foo' => 'bar'];
42-
(new RequestParameters($parts, [], $data))->getInt('foo');
42+
(new RequestParameters($parts, varray[], $data))->getInt('foo');
4343
})->toThrow(InvariantException::class);
4444
}
4545

4646
public function testEnumParam(): void {
47-
$parts = [new EnumRequestParameter(TestIntEnum::class, 'foo')];
47+
$parts = varray[new EnumRequestParameter(TestIntEnum::class, 'foo')];
4848
$data = dict['foo' => (string)TestIntEnum::BAR];
49-
$value = (new RequestParameters($parts, [], $data))->getEnum(
49+
$value = (new RequestParameters($parts, varray[], $data))->getEnum(
5050
TestIntEnum::class,
5151
'foo',
5252
);
@@ -85,7 +85,7 @@ public function testFromPattern(): void {
8585
'bar' => '123',
8686
'baz' => (string)TestIntEnum::FOO,
8787
];
88-
$params = new RequestParameters($parts, [], $data);
88+
$params = new RequestParameters($parts, varray[], $data);
8989
expect($params->getString('foo'))->toBeSame('some string');
9090
expect($params->getInt('bar'))->toBeSame(123);
9191
expect($params->getEnum(TestIntEnum::class, 'baz'))->toBeSame(
@@ -95,8 +95,8 @@ public function testFromPattern(): void {
9595

9696
public function testGetOptional(): void {
9797
$params = new RequestParameters(
98-
[],
99-
[new StringRequestParameter(
98+
varray[],
99+
varray[new StringRequestParameter(
100100
StringRequestParameterSlashes::WITHOUT_SLASHES,
101101
'foo',
102102
)],
@@ -107,8 +107,8 @@ public function testGetOptional(): void {
107107

108108
public function testGetMissingOptional(): void {
109109
$params = new RequestParameters(
110-
[],
111-
[new StringRequestParameter(
110+
varray[],
111+
varray[new StringRequestParameter(
112112
StringRequestParameterSlashes::WITHOUT_SLASHES,
113113
'foo',
114114
)],
@@ -120,8 +120,8 @@ public function testGetMissingOptional(): void {
120120
public function testGetOptionalAsRequired(): void {
121121
expect(() ==> {
122122
$params = new RequestParameters(
123-
[],
124-
[new StringRequestParameter(
123+
varray[],
124+
varray[new StringRequestParameter(
125125
StringRequestParameterSlashes::WITHOUT_SLASHES,
126126
'foo',
127127
)],
@@ -134,11 +134,11 @@ public function testGetOptionalAsRequired(): void {
134134
public function testGetRequiredAsOptional(): void {
135135
expect(() ==> {
136136
$params = new RequestParameters(
137-
[new StringRequestParameter(
137+
varray[new StringRequestParameter(
138138
StringRequestParameterSlashes::WITHOUT_SLASHES,
139139
'foo',
140140
)],
141-
[],
141+
varray[],
142142
dict['foo' => 'bar'],
143143
);
144144
$params->getOptionalString('foo');

tests/RouterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ final class RouterTest extends \Facebook\HackTest\HackTest {
3838
];
3939

4040
public function expectedMatches(
41-
): array<(string, string, dict<string, string>)> {
42-
return [
41+
): varray<(string, string, dict<string, string>)> {
42+
return varray[
4343
tuple('/foo', '/foo', dict[]),
4444
tuple('/foo/', '/foo/', dict[]),
4545
tuple('/foo/bar', '/foo/bar', dict[]),
@@ -96,7 +96,7 @@ public function getAllResolvers(
9696
(function(dict<HttpMethod, dict<string, string>>): IResolver<string>),
9797
)
9898
> {
99-
return [
99+
return varray[
100100
tuple('simple regexp', $map ==> new SimpleRegexpResolver($map)),
101101
tuple(
102102
'prefix matching',
@@ -110,7 +110,7 @@ public function expectedMatchesWithResolvers(
110110
$map = dict[HttpMethod::GET => dict(self::MAP)];
111111
$resolvers = Dict\from_entries($this->getAllResolvers());
112112

113-
$out = [];
113+
$out = varray[];
114114
$examples = $this->expectedMatches();
115115
foreach ($resolvers as $name => $resolver) {
116116
$resolver = $resolver($map);

tests/UriPatternTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function testIntParamAssertSucceeds(): void {
7171
)->toBeSame((new IntRequestParameter('foo'))->assert('123'));
7272
}
7373

74-
public function exampleInvalidInts(): array<array<string>> {
75-
return [['foo'], ['0123foo'], ['0.123foo'], ['0.123'], ['0x1e3']];
74+
public function exampleInvalidInts(): varray<varray<string>> {
75+
return varray[varray['foo'], varray['0123foo'], varray['0.123foo'], varray['0.123'], varray['0x1e3']];
7676
}
7777

7878
<<DataProvider('exampleInvalidInts')>>

0 commit comments

Comments
 (0)