diff --git a/tests/PHPStan/Analyser/nsrt/bug-13385b.php b/tests/PHPStan/Analyser/nsrt/bug-13385b.php new file mode 100644 index 0000000000..64864b11ae --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13385b.php @@ -0,0 +1,51 @@ + $children + */ + public function calculate(array $children): int { + $operands = []; + $operators = []; + + foreach ($children as $child) { + if ($child instanceof Operator) { + while ($operators !== []) { + $op = array_pop($operators); + $left = array_pop($operands) ?? 0; + $right = array_pop($operands) ?? 0; + + assert(is_int($left)); + assert(is_int($right)); + + $value = $op->calculate($left, $right); + + assertType(Operator::class, $op); + assertType('int', $left); + assertType('int', $right); + assertType('int', $value); + + $operands[] = $value; + + assertType('non-empty-list', $operands); + } + + $operators[] = $child; + } else { + $operands[] = $child; + } + } + + return count($operands) === 1 ? reset($operands) : 0; + } +}