Skip to content
Merged
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
2 changes: 1 addition & 1 deletion doc/grammars/type.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 1 addition & 13 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,17 @@ public function provideParseData(): array
false
),
],
[
'?Currency::CURRENCY_*',
new NullableTypeNode(
new ConstTypeNode(
new ConstFetchNode(
'Currency',
'CURRENCY_*'
)
)
),
],
];
}

Expand Down