From 0cae9edacf1f17dc0449e9a6bcc7cb38fa7a213a Mon Sep 17 00:00:00 2001 From: jjergus Date: Mon, 17 Aug 2020 12:20:52 -0700 Subject: [PATCH] don't use is_* functions for arrays is_array not supported in HHVM 4.71+ others not supported before HHVM 4.45 is/as expressions work across all versions we don't care about the exact array type here, so using the most generic available interface everywhere --- src/HHClientFallbackHandler.hack | 7 ++++--- src/TypeAssert.hack | 18 +++++------------- src/builders/FactParseScanner.hack | 5 ++++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/HHClientFallbackHandler.hack b/src/HHClientFallbackHandler.hack index e8bab3a..d808262 100644 --- a/src/HHClientFallbackHandler.hack +++ b/src/HHClientFallbackHandler.hack @@ -232,13 +232,14 @@ class HHClientFallbackHandler extends FailureHandler { } $data = \json_decode($last, /* assoc = */ true); - if (!\HH\is_any_array($data)) { + if (!$data is Traversable<_>) { return null; } foreach ($data as $row) { + $row as KeyedContainer<_, _>; if ($row['name'] === $name) { - $file = $row['filename']; - if (\substr($file, -4) === '.hhi') { + $file = $row['filename'] as ?string; + if ($file is null || \substr($file, -4) === '.hhi') { return null; } return $file; diff --git a/src/TypeAssert.hack b/src/TypeAssert.hack index bb0adeb..fe413bf 100644 --- a/src/TypeAssert.hack +++ b/src/TypeAssert.hack @@ -32,7 +32,7 @@ function is_nullable_bool(mixed $value, string $field): ?bool { } function is_array_of_strings(mixed $value, string $field): varray { - invariant(\HH\is_any_array($value), '%s should be an array', $field); + invariant($value is Container<_>, '%s should be an array', $field); $out = varray[]; foreach ($value as $it) { invariant($it is string, '%s should be an array', $field); @@ -42,11 +42,7 @@ function is_array_of_strings(mixed $value, string $field): varray { } function is_vec_like_of_strings(mixed $value, string $field): vec { - invariant( - $value is vec<_> || \HH\is_php_array($value), - '%s should be a vec', - $field, - ); + invariant($value is Traversable<_>, '%s should be a vec', $field); $out = vec[]; foreach ($value as $el) { invariant($el is string, '%s should be a vec', $field); @@ -63,11 +59,7 @@ function is_nullable_vec_like_of_strings( return null; } - invariant( - \HH\is_php_array($value) || $value is vec<_>, - '%s should be an ?vec', - $field, - ); + invariant($value is Traversable<_>, '%s should be an ?vec', $field); $out = vec[]; foreach ($value as $it) { invariant($it is string, '%s should be an ?vec', $field); @@ -95,10 +87,10 @@ function is_array_of_shapes_with_name_field( string $field, ): varray string)> { $msg = $field.'should be an array string)>'; - invariant(\HH\is_any_array($value), '%s', $msg); + invariant($value is Traversable<_>, '%s', $msg); $out = varray[]; foreach ($value as $it) { - invariant(\HH\is_any_array($it), '%s', $msg); + invariant($it is KeyedContainer<_, _>, '%s', $msg); $name = $it['name'] ?? null; invariant($name is string, '%s', $msg); $out[] = shape('name' => $name); diff --git a/src/builders/FactParseScanner.hack b/src/builders/FactParseScanner.hack index 3f34c6c..057ec63 100644 --- a/src/builders/FactParseScanner.hack +++ b/src/builders/FactParseScanner.hack @@ -23,7 +23,10 @@ final class FactParseScanner implements Builder { )>; private static function untypedToShape(mixed $data): self::TFacts { - invariant(\HH\is_any_array($data), 'FactsParse did not give us an array'); + invariant( + $data is KeyedTraversable<_, _>, + 'FactsParse did not give us an array', + ); $out = darray[]; foreach ($data as $file => $facts) {