Wildcard constants

This commit is contained in:
Ondrej Mirtes 2020-04-30 16:17:27 +02:00
parent 4f03df6e39
commit 3170d7d858
No known key found for this signature in database
GPG Key ID: 8E730BA25823D8B5
2 changed files with 17 additions and 0 deletions

View File

@ -111,6 +111,12 @@ class TypeParser
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
throw $exception;
}
if ($constExpr instanceof Ast\ConstExpr\ConstFetchNode) {
if ($tokens->currentTokenValue() === '*') {
$tokens->consumeTokenType($tokens->currentTokenType());
$constExpr = new Ast\ConstExpr\ConstFetchNode($constExpr->className, $constExpr->name . '*');
}
}
return new Ast\Type\ConstTypeNode($constExpr);
} catch (\LogicException $e) {
throw $exception;

View File

@ -854,6 +854,17 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
'"bar"',
new ConstTypeNode(new ConstExprStringNode('bar')),
],
[
'Foo::FOO_*',
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*')),
],
[
'( "foo" | Foo::FOO_* )',
new UnionTypeNode([
new ConstTypeNode(new ConstExprStringNode('foo')),
new ConstTypeNode(new ConstFetchNode('Foo', 'FOO_*')),
]),
],
];
}