diff --git a/doc/grammars/type.abnf b/doc/grammars/type.abnf index d28a768b..5af5be1f 100644 --- a/doc/grammars/type.abnf +++ b/doc/grammars/type.abnf @@ -20,7 +20,7 @@ Conditional = 1*ByteHorizontalWs TokenIs [TokenNot] Atomic TokenNullable Atomic TokenColon Atomic Nullable - = TokenNullable TokenIdentifier [Generic] + = TokenNullable Atomic Atomic = TokenIdentifier [Generic / Callable / Array] diff --git a/src/Parser/TypeParser.php b/src/Parser/TypeParser.php index cdfd9a29..170b2581 100644 --- a/src/Parser/TypeParser.php +++ b/src/Parser/TypeParser.php @@ -282,19 +282,7 @@ private function parseNullable(TokenIterator $tokens): Ast\Type\TypeNode { $tokens->consumeTokenType(Lexer::TOKEN_NULLABLE); - $type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue()); - $tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER); - - 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()) { - $type = $this->parseArrayShape($tokens, $type); - } - - if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) { - $type = $this->tryParseArrayOrOffsetAccess($tokens, $type); - } + $type = $this->parseAtomic($tokens); return new Ast\Type\NullableTypeNode($type); } diff --git a/tests/PHPStan/Parser/TypeParserTest.php b/tests/PHPStan/Parser/TypeParserTest.php index 52402048..8289488b 100644 --- a/tests/PHPStan/Parser/TypeParserTest.php +++ b/tests/PHPStan/Parser/TypeParserTest.php @@ -1255,6 +1255,17 @@ public function provideParseData(): array false ), ], + [ + '?Currency::CURRENCY_*', + new NullableTypeNode( + new ConstTypeNode( + new ConstFetchNode( + 'Currency', + 'CURRENCY_*' + ) + ) + ), + ], ]; }