diff --git a/src/Parser/TypeParser.php b/src/Parser/TypeParser.php index 9e8956f5..ffe10bb5 100644 --- a/src/Parser/TypeParser.php +++ b/src/Parser/TypeParser.php @@ -521,17 +521,7 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo $startLine = $tokens->currentTokenLine(); $startIndex = $tokens->currentTokenIndex(); if ($tokens->isCurrentTokenType(Lexer::TOKEN_NULLABLE)) { - $type = $this->parseNullable($tokens); - if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) { - $type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes( - $tokens, - $type, - $startLine, - $startIndex - )); - } - - return $type; + return $this->parseNullable($tokens); } elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) { $type = $this->parse($tokens); diff --git a/tests/PHPStan/Parser/TypeParserTest.php b/tests/PHPStan/Parser/TypeParserTest.php index 0fcb0e3b..b16f7b01 100644 --- a/tests/PHPStan/Parser/TypeParserTest.php +++ b/tests/PHPStan/Parser/TypeParserTest.php @@ -2014,6 +2014,18 @@ public function provideParseData(): array 'callable(): Foo::*', new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ConstTypeNode(new ConstFetchNode('Foo', '*'))), ], + [ + '?Foo[]', + new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo'))), + ], + [ + 'callable(): ?Foo', + new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new IdentifierTypeNode('Foo'))), + ], + [ + 'callable(): ?Foo[]', + new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo')))), + ], ]; }