Skip to content

Commit 1e355a3

Browse files
authored
Support all atomic types as nullable types
1 parent 7c621a2 commit 1e355a3

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

Diff for: doc/grammars/type.abnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Conditional
2020
= 1*ByteHorizontalWs TokenIs [TokenNot] Atomic TokenNullable Atomic TokenColon Atomic
2121

2222
Nullable
23-
= TokenNullable TokenIdentifier [Generic]
23+
= TokenNullable Atomic
2424

2525
Atomic
2626
= TokenIdentifier [Generic / Callable / Array]

Diff for: src/Parser/TypeParser.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,7 @@ private function parseNullable(TokenIterator $tokens): Ast\Type\TypeNode
282282
{
283283
$tokens->consumeTokenType(Lexer::TOKEN_NULLABLE);
284284

285-
$type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue());
286-
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
287-
288-
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
289-
$type = $this->parseGeneric($tokens, $type);
290-
291-
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
292-
$type = $this->parseArrayShape($tokens, $type);
293-
}
294-
295-
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
296-
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
297-
}
285+
$type = $this->parseAtomic($tokens);
298286

299287
return new Ast\Type\NullableTypeNode($type);
300288
}

Diff for: tests/PHPStan/Parser/TypeParserTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,17 @@ public function provideParseData(): array
12551255
false
12561256
),
12571257
],
1258+
[
1259+
'?Currency::CURRENCY_*',
1260+
new NullableTypeNode(
1261+
new ConstTypeNode(
1262+
new ConstFetchNode(
1263+
'Currency',
1264+
'CURRENCY_*'
1265+
)
1266+
)
1267+
),
1268+
],
12581269
];
12591270
}
12601271

0 commit comments

Comments
 (0)