Skip to content

Commit df42dc9

Browse files
lexidorjjergus
authored andcommittedOct 31, 2019
Support disallow_array_literal (#119)
* 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 235e13d commit df42dc9

10 files changed

+23
-22
lines changed
 

‎.hhconfig

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ enable_experimental_tc_features=shape_field_check,sealed_classes
99
user_attributes=
1010
disable_primitive_refinement=true
1111
disallow_stringish_magic=true
12+
disallow_array_literal = true
1213
disallow_silence = true

‎.travis.yml

+1-1
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.13-latest
5+
- HHVM_VERSION=4.25-latest
66
- HHVM_VERSION=latest
77
- HHVM_VERSION=nightly
88
install:

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Hack Codegen is a library for programatically generating Hack code",
44
"keywords": ["code generation", "Hack"],
55
"require": {
6-
"hhvm": "^4.13.0",
6+
"hhvm": "^4.25",
77
"hhvm/hhvm-autoload": "^2.0",
88
"hhvm/hsl": "^4.0"
99
},

‎examples/dorm/CodegenDorm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private function getGetters(): Vector<CodegenMethod> {
184184
}
185185

186186
private function getDatabaseRowShape(): CodegenShape {
187-
$db_fields = array();
187+
$db_fields = varray[];
188188
foreach ($this->schema->getFields() as $field) {
189189
$type = $field->getType();
190190
if ($type === \DateTime::class) {

‎src/CodegenClassish.hack

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ abstract class CodegenClassish implements ICodeBuilderRenderer {
380380
$generated_from =
381381
$this->generatedFrom ? $this->generatedFrom->render() : null;
382382

383-
$doc_block_parts = \array_filter(array($this->docBlock, $generated_from));
383+
$doc_block_parts = \array_filter(varray[$this->docBlock, $generated_from]);
384384

385385
if ($doc_block_parts) {
386386
$builder->addDocBlock(\implode("\n\n", $doc_block_parts));

‎src/CodegenFile.hack

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ final class CodegenFile {
463463
private function loadExistingFiles(): ?string {
464464
$file_names = $this->otherFileNames;
465465
$file_names[] = $this->fileName;
466-
$all_content = array();
466+
$all_content = varray[];
467467
foreach ($file_names as $file_name) {
468468
if (\file_exists($file_name)) {
469469
$content = Filesystem::readFile($file_name);

‎src/HackfmtFormatter.hack

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class HackfmtFormatter implements ICodegenFormatter {
2121
string $code,
2222
string $_file_name,
2323
): string {
24-
$output = array();
24+
$output = varray[];
2525
$exit_code = null;
2626

2727
$tempnam = \tempnam(

‎src/PartiallyGeneratedCode.hack

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class PartiallyGeneratedCode {
5555
string $existing_code,
5656
?KeyedContainer<string, Traversable<string>> $rekeys = null,
5757
): string {
58-
$merged = array();
58+
$merged = varray[];
5959
$existing = $this->extractManualCode($existing_code);
6060
$generated = $this->iterateCodeSections($this->code);
6161
foreach ($generated as $section) {
@@ -110,7 +110,7 @@ final class PartiallyGeneratedCode {
110110
* Extract the generated code and returns it as a string.
111111
*/
112112
public function extractGeneratedCode(): string {
113-
$generated = array();
113+
$generated = varray[];
114114
foreach ($this->iterateCodeSections($this->code) as $section) {
115115
list($id, $chunk) = $section;
116116
if ($id === null) {
@@ -146,12 +146,12 @@ final class PartiallyGeneratedCode {
146146

147147
$seen_ids = keyset[];
148148
$current_id = null;
149-
$chunk = array();
149+
$chunk = varray[];
150150
$lines = \explode("\n", $code);
151151
foreach ($lines as $line) {
152152
if (\strpos($line, self::$manualEnd) !== false) {
153153
yield tuple($current_id, \implode("\n", $chunk));
154-
$chunk = array($line);
154+
$chunk = varray[$line];
155155
$current_id = null;
156156

157157
} else if (\preg_match($begin, $line) === 1) {
@@ -168,7 +168,7 @@ final class PartiallyGeneratedCode {
168168

169169
$chunk[] = $line;
170170
yield tuple(null, \implode("\n", $chunk));
171-
$chunk = array();
171+
$chunk = varray[];
172172
$current_id = \trim(\preg_replace($begin, '\\1', $line));
173173

174174
if (C\contains($seen_ids, $current_id)) {

‎tests/CodegenPropertyTest.hack

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class CodegenPropertyTest extends CodegenBaseTest {
5555
->codegenProperty('languages')
5656
->setIsStatic()
5757
->setValue(
58-
array('en' => 'English', 'es' => 'Spanish', 'fr' => 'French'),
58+
darray['en' => 'English', 'es' => 'Spanish', 'fr' => 'French'],
5959
HackBuilderValues::export(),
6060
)
6161
->render();

‎tests/HackBuilderTest.hack

+10-10
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ $del."extends SomeBaseClass",
274274
->startIfBlock('$do_that')
275275
->add('return ')
276276
->addValue(
277-
array(1, 2, 3),
277+
varray[1, 2, 3],
278278
HackBuilderValues::valueArray(HackBuilderValues::export()),
279279
)
280280
->closeStatement()
@@ -286,9 +286,9 @@ $del."extends SomeBaseClass",
286286
public function testSwitchBodyWithReturnsInCaseAndDefault(): void {
287287
// Gosh, I have no idea what names of football shots are!
288288
$players = Vector {
289-
array('name' => 'Ronaldo', 'favorite_shot' => 'freeKick'),
290-
array('name' => 'Messi', 'favorite_shot' => 'slideKick'),
291-
array('name' => 'Maradona', 'favorite_shot' => 'handOfGod'),
289+
darray['name' => 'Ronaldo', 'favorite_shot' => 'freeKick'],
290+
darray['name' => 'Messi', 'favorite_shot' => 'slideKick'],
291+
darray['name' => 'Maradona', 'favorite_shot' => 'handOfGod'],
292292
};
293293

294294
$body = $this
@@ -313,9 +313,9 @@ $del."extends SomeBaseClass",
313313
public function testSwitchBodyWithBreaksInCaseAndDefault(): void {
314314
// Gosh, I have no idea what names of football shots are!
315315
$players = Vector {
316-
array('name' => 'Ronaldo', 'favorite_shot' => 'freeKick'),
317-
array('name' => 'Messi', 'favorite_shot' => 'slideKick'),
318-
array('name' => 'Maradona', 'favorite_shot' => 'handOfGod'),
316+
darray['name' => 'Ronaldo', 'favorite_shot' => 'freeKick'],
317+
darray['name' => 'Messi', 'favorite_shot' => 'slideKick'],
318+
darray['name' => 'Maradona', 'favorite_shot' => 'handOfGod'],
319319
};
320320

321321
$body = $this
@@ -340,9 +340,9 @@ $del."extends SomeBaseClass",
340340
public function testSwitchBodyWithMultipleCasesWithoutBreaks(): void {
341341
// Gosh, I have no idea what names of football shots are!
342342
$players = Vector {
343-
array('name' => 'Ronaldo', 'favorite_shot' => 'freeKick'),
344-
array('name' => 'Messi', 'favorite_shot' => 'slideKick'),
345-
array('name' => 'Maradona', 'favorite_shot' => 'handOfGod'),
343+
darray['name' => 'Ronaldo', 'favorite_shot' => 'freeKick'],
344+
darray['name' => 'Messi', 'favorite_shot' => 'slideKick'],
345+
darray['name' => 'Maradona', 'favorite_shot' => 'handOfGod'],
346346
};
347347

348348
$body = $this

0 commit comments

Comments
 (0)
Please sign in to comment.