phpdoc-parser icon indicating copy to clipboard operation
phpdoc-parser copied to clipboard

stdClass|Iterator&Throwable is parsed as stdClass|Iterator

Open vudaltsov opened this issue 8 months ago • 1 comments

I would expect an error or stdClass|(Iterator&Throwable), since "and" usually has higher precedence than "or".

vudaltsov avatar Mar 27 '25 01:03 vudaltsov

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".

vudaltsov avatar Mar 27 '25 10:03 vudaltsov