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

Commit 0983260

Browse files
committed
support older HHVM releases
is_vec_or_varray, is_dict_or_darray, is_any_array not available until HHVM 4.65
1 parent 5b446e4 commit 0983260

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/TypeSpec/__Private/ShapeSpec.hack

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final class ShapeSpec extends TypeSpec<shape()> {
6767

6868
<<__Override>>
6969
public function assertType(mixed $value): shape() {
70-
if (!\HH\is_dict_or_darray($value)) {
70+
if (!(\HH\is_php_array($value) || ($value is dict<_, _>))) {
7171
throw IncorrectTypeException::withValue(
7272
$this->getTrace(),
7373
'shape',
@@ -80,9 +80,7 @@ final class ShapeSpec extends TypeSpec<shape()> {
8080
foreach ($this->inners as $key => $spec) {
8181
$trace = $this->getTrace()->withFrame('shape['.$key.']');
8282
if (C\contains_key($value, $key)) {
83-
// Using idx() even though we just checked the key's existence, to avoid
84-
// a Hack error.
85-
$out[$key] = $spec->withTrace($trace)->assertType(idx($value, $key));
83+
$out[$key] = $spec->withTrace($trace)->assertType($value[$key] ?? null);
8684
continue;
8785
}
8886

src/TypeSpec/__Private/TupleSpec.hack

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class TupleSpec extends TypeSpec<BogusTuple> {
2222

2323
<<__Override>>
2424
public function coerceType(mixed $value): BogusTuple {
25-
if (!\HH\is_vec_or_varray($value)) {
25+
if (!(\HH\is_php_array($value) || ($value is vec<_>))) {
2626
throw
2727
TypeCoercionException::withValue($this->getTrace(), 'tuple', $value);
2828
}
@@ -49,13 +49,12 @@ final class TupleSpec extends TypeSpec<BogusTuple> {
4949

5050
<<__Override>>
5151
public function assertType(mixed $value): BogusTuple {
52-
if (!\HH\is_vec_or_varray($value)) {
52+
if (\HH\is_php_array($value)) {
53+
$value = vec($value);
54+
} else if (!($value is vec<_>)) {
5355
throw
5456
IncorrectTypeException::withValue($this->getTrace(), 'tuple', $value);
5557
}
56-
if (!$value is vec<_>) {
57-
$value = vec($value);
58-
}
5958
$values = $value;
6059

6160
$count = \count($values);

0 commit comments

Comments
 (0)