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

Commit 27909c5

Browse files
committed
Create real darrays for shapes.
refs facebook/hhvm#8343 Not sure if `as` requiring darrays is a bug or not, but this is also correct, so let's do it.
1 parent e9c6d1f commit 27909c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/TypeSpec/__Private/ShapeSpec.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private static function dictToShapeUNSAFE(
120120
/* HH_IGNORE_ERROR[4110] */
121121
return $shape;
122122
}
123-
/* HH_IGNORE_ERROR[4007] */
124-
return (array)$shape;
123+
/* HH_FIXME[2049] */
124+
/* HH_FIXME[4107] */
125+
return \darray($shape);
125126
}
126127
}

tests/TypeStructureTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ public function testValidType<T>(TypeStructure<T> $ts, T $input): void {
216216
->toBeSame($input);
217217
}
218218

219+
public function testAssertedShapeAsShape(): void {
220+
// most of the runtime is fine with actual PHP arrays, but we need a real
221+
// darray for the `as` operator
222+
$x = shape('someString' => 'foo');
223+
$y = TypeAssert\matches_type_structure(
224+
type_structure(TypeConstants::class, 'TShapeWithOneField'),
225+
$x,
226+
);
227+
$z = $y as TypeConstants::TShapeWithOneField;
228+
}
229+
219230
public function getExampleInvalidTypes(
220231
): array<string, (mixed, mixed, vec<string>)> {
221232
$examples = [

0 commit comments

Comments
 (0)