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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/Parser/ConstExprParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,29 @@ public function parse(TokenIterator $tokens, bool $trimStrings = false): Ast\Con

if ($tokens->tryConsumeTokenType(Lexer::TOKEN_DOUBLE_COLON)) {
$classConstantName = '';
if ($tokens->currentTokenType() === Lexer::TOKEN_IDENTIFIER) {
$classConstantName .= $tokens->currentTokenValue();
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_WILDCARD)) {
$lastType = null;
while (true) {
if ($lastType !== Lexer::TOKEN_IDENTIFIER && $tokens->currentTokenType() === Lexer::TOKEN_IDENTIFIER) {
$classConstantName .= $tokens->currentTokenValue();
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
$lastType = Lexer::TOKEN_IDENTIFIER;

continue;
}

if ($lastType !== Lexer::TOKEN_WILDCARD && $tokens->tryConsumeTokenType(Lexer::TOKEN_WILDCARD)) {
$classConstantName .= '*';
$lastType = Lexer::TOKEN_WILDCARD;

continue;
}
} else {
$tokens->consumeTokenType(Lexer::TOKEN_WILDCARD);
$classConstantName .= '*';

if ($lastType === null) {
// trigger parse error if nothing valid was consumed
$tokens->consumeTokenType(Lexer::TOKEN_WILDCARD);
}

break;
}

return new Ast\ConstExpr\ConstFetchNode($identifier, $classConstantName);
Expand Down
19 changes: 17 additions & 2 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,22 @@ public function provideParseData(): array
'Foo::FOO_*',
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*')),
],
[
'Foo::FOO_*BAR',
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*BAR')),
],
[
'Foo::*FOO*',
new ConstTypeNode(new ConstFetchNode('Foo', '*FOO*')),
],
[
'Foo::A*B*C',
new ConstTypeNode(new ConstFetchNode('Foo', 'A*B*C')),
],
[
'self::*BAR',
new ConstTypeNode(new ConstFetchNode('self', '*BAR')),
],
[
'Foo::*',
new ConstTypeNode(new ConstFetchNode('Foo', '*')),
Expand All @@ -869,8 +885,7 @@ public function provideParseData(): array
],
[
'Foo::*a',
new ConstTypeNode(new ConstFetchNode('Foo', '*')), // fails later in PhpDocParser
Lexer::TOKEN_IDENTIFIER,
new ConstTypeNode(new ConstFetchNode('Foo', '*a')),
],
[
'( "foo" | Foo::FOO_* )',
Expand Down