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

Commit e21656f

Browse files
committed
Fix :xhp::__construct $children type
Hack now typechecks XHP constructors (facebook/hhvm@af6f350) which revealed this error.
1 parent 55bbdcb commit e21656f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/core/ComposableElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function init(): void {
3535
*/
3636
final public function __construct(
3737
KeyedTraversable<string, mixed> $attributes,
38-
Traversable<XHPChild> $children,
38+
Traversable<?XHPChild> $children,
3939
dynamic ...$debug_info
4040
) {
4141
parent::__construct($attributes, $children);

src/core/XHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class :xhp implements XHPChild, JsonSerializable {
1616

1717
public function __construct(
1818
KeyedTraversable<string, mixed> $attributes,
19-
Traversable<XHPChild> $children,
19+
Traversable<?XHPChild> $children,
2020
): void {
2121
}
2222
abstract public function appendChild(mixed $child): this;

tests/BasicsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function testXFrag(): void {
5050
expect($xhp->toString())->toEqual('<div>herpderp</div>');
5151
}
5252

53+
public async function testScalarChildren(): Awaitable<void> {
54+
$xhp = <div>{42}{' str '}{3.14}{null}</div>;
55+
expect($xhp->toString())->toEqual('<div>42 str 3.14</div>');
56+
}
57+
5358
public function testEscaping(): void {
5459
$xhp = <div>{"foo<SCRIPT>bar"}</div>;
5560
expect($xhp->toString())->toEqual('<div>foo&lt;SCRIPT&gt;bar</div>');

0 commit comments

Comments
 (0)