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

Commit 5b446e4

Browse files
committed
replace all is_array() calls
1 parent 5a3f382 commit 5b446e4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/TypeSpec/__Private/ShapeSpec.hack

Lines changed: 4 additions & 2 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 (!(\is_array($value) || ($value is dict<_, _>))) {
70+
if (!\HH\is_dict_or_darray($value)) {
7171
throw IncorrectTypeException::withValue(
7272
$this->getTrace(),
7373
'shape',
@@ -80,7 +80,9 @@ 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-
$out[$key] = $spec->withTrace($trace)->assertType($value[$key] ?? null);
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));
8486
continue;
8587
}
8688

src/TypeSpec/__Private/TupleSpec.hack

Lines changed: 5 additions & 4 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 (!(\is_array($value) || ($value is vec<_>))) {
25+
if (!\HH\is_vec_or_varray($value)) {
2626
throw
2727
TypeCoercionException::withValue($this->getTrace(), 'tuple', $value);
2828
}
@@ -49,12 +49,13 @@ final class TupleSpec extends TypeSpec<BogusTuple> {
4949

5050
<<__Override>>
5151
public function assertType(mixed $value): BogusTuple {
52-
if (\is_array($value)) {
53-
$value = vec($value);
54-
} else if (!($value is vec<_>)) {
52+
if (!\HH\is_vec_or_varray($value)) {
5553
throw
5654
IncorrectTypeException::withValue($this->getTrace(), 'tuple', $value);
5755
}
56+
if (!$value is vec<_>) {
57+
$value = vec($value);
58+
}
5859
$values = $value;
5960

6061
$count = \count($values);

src/TypeSpec/__Private/UntypedArraySpec.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class UntypedArraySpec extends TypeSpec<varray_or_darray<mixed>> {
3131

3232
<<__Override>>
3333
public function assertType(mixed $value): varray_or_darray<mixed> {
34-
if (!\is_array($value)) {
34+
if (!\HH\is_php_array($value)) {
3535
throw
3636
IncorrectTypeException::withValue($this->getTrace(), 'array', $value);
3737
}

0 commit comments

Comments
 (0)