Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use LogicException;
use PHPStan\PhpDocParser\Ast;
use PHPStan\PhpDocParser\Lexer\Lexer;
use function in_array;
use function strpos;
use function trim;

Expand Down Expand Up @@ -123,7 +124,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);

} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
} elseif (in_array($type->name, ['array', 'list', 'strict-array', 'strict-list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
$type = $this->parseArrayShape($tokens, $type);

if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
Expand Down Expand Up @@ -409,7 +410,7 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
$type = $this->parseGeneric($tokens, $type);

} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
} elseif (in_array($type->name, ['array', 'list', 'strict-array', 'strict-list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
$type = $this->parseArrayShape($tokens, $type);
}
}
Expand Down
54 changes: 54 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,60 @@ public function provideParseData(): array
),
]),
],
[
'strict-array{
a: int,
b: string
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
new IdentifierTypeNode('a'),
false,
new IdentifierTypeNode('int')
),
new ArrayShapeItemNode(
new IdentifierTypeNode('b'),
false,
new IdentifierTypeNode('string')
),
]),
],
[
'strict-list{
int,
string
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('int')
),
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('string')
),
]),
],
[
'list{
int,
string
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('int')
),
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('string')
),
]),
],
[
'callable(): Foo',
new CallableTypeNode(
Expand Down