diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index bc85f76..804026e 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -66,7 +66,7 @@ abstract class PrettyPrinterAbstract BinaryOp\BooleanAnd::class => [120, -1], BinaryOp\BooleanOr::class => [130, -1], BinaryOp\Coalesce::class => [140, 1], - Expr\Ternary::class => [150, -1], + Expr\Ternary::class => [150, 0], // parser uses %left for assignments, but they really behave as %right Expr\Assign::class => [160, 1], Expr\AssignRef::class => [160, 1], diff --git a/test/code/prettyPrinter/expr/parentheses.test b/test/code/prettyPrinter/expr/parentheses.test index a49c110..bda956e 100644 --- a/test/code/prettyPrinter/expr/parentheses.test +++ b/test/code/prettyPrinter/expr/parentheses.test @@ -59,7 +59,7 @@ $a = $b = $c = $d = $f && true; ($a = $b = $c = $d = $f) && true; $a = $b = $c = $d = $f and true; $a = $b = $c = $d = ($f and true); -$a ? $b : $c ? $d : $e ? $f : $g; +(($a ? $b : $c) ? $d : $e) ? $f : $g; $a ? $b : ($c ? $d : ($e ? $f : $g)); $a ? $b ? $c : $d : $f; $a ?? $b ?? $c;