Skip to content

Commit

Permalink
Avoid crash when callable type is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 15, 2020
1 parent cb3a793 commit 1ddc6af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Psalm/Internal/Type/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,18 @@ function (ParseTree $child_tree) use (
$is_optional = false;

if ($child_tree instanceof ParseTree\CallableParamTree) {
$tree_type = self::getTypeFromTree(
$child_tree->children[0],
$codebase,
null,
$template_type_map,
$type_aliases
);
if (isset($child_tree->children[0])) {
$tree_type = self::getTypeFromTree(
$child_tree->children[0],
$codebase,
null,
$template_type_map,
$type_aliases
);
} else {
$tree_type = new TMixed();
}

$is_variadic = $child_tree->variadic;
$is_optional = $child_tree->has_default;
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/TypeParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ public function testCallableWithAnotherBadVariadic(): void
Type::parseString('callable(int, string..) : void');
}

public function testCallableWithMissingVariadicType(): void
{
$this->assertSame(
'callable(mixed...):void',
(string) Type::parseString('callable(...): void')
);
}

public function testCallableWithVariadicAndDefault(): void
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Expand Down

0 comments on commit 1ddc6af

Please sign in to comment.