Skip to content

Commit 3170d7d

Browse files
committed
Wildcard constants
1 parent 4f03df6 commit 3170d7d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Parser/TypeParser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
111111
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
112112
throw $exception;
113113
}
114+
if ($constExpr instanceof Ast\ConstExpr\ConstFetchNode) {
115+
if ($tokens->currentTokenValue() === '*') {
116+
$tokens->consumeTokenType($tokens->currentTokenType());
117+
$constExpr = new Ast\ConstExpr\ConstFetchNode($constExpr->className, $constExpr->name . '*');
118+
}
119+
}
114120
return new Ast\Type\ConstTypeNode($constExpr);
115121
} catch (\LogicException $e) {
116122
throw $exception;

tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,17 @@ public function provideParseData(): array
854854
'"bar"',
855855
new ConstTypeNode(new ConstExprStringNode('bar')),
856856
],
857+
[
858+
'Foo::FOO_*',
859+
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*')),
860+
],
861+
[
862+
'( "foo" | Foo::FOO_* )',
863+
new UnionTypeNode([
864+
new ConstTypeNode(new ConstExprStringNode('foo')),
865+
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*')),
866+
]),
867+
],
857868
];
858869
}
859870

0 commit comments

Comments
 (0)