phpdoc-parser
phpdoc-parser copied to clipboard
stdClass|Iterator&Throwable is parsed as stdClass|Iterator
I would expect an error or stdClass|(Iterator&Throwable), since "and" usually has higher precedence than "or".
Reproducer:
<?php
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use PHPStan\PhpDocParser\Printer\Printer;
require_once __DIR__.'/../vendor/autoload.php';
$config = new ParserConfig(usedAttributes: []);
$lexer = new Lexer($config);
$constExprParser = new ConstExprParser($config);
$typeParser = new TypeParser($config, $constExprParser);
$tokens = new TokenIterator($lexer->tokenize('stdClass|Iterator&Throwable'));
$type = $typeParser->parse($tokens);
var_dump((new Printer())->print($type));
On version 2.1.0 it outputs string(17) "stdClass|Iterator".