Throw if pretty-printing Error node

This commit is contained in:
Nikita Popov 2017-01-29 21:56:21 +01:00
parent ba57202ed7
commit fd7ac25108
2 changed files with 14 additions and 0 deletions

View File

@ -485,6 +485,10 @@ class Standard extends PrettyPrinterAbstract
// Other
protected function pExpr_Error(Expr\Error $node) {
throw new \LogicException('Cannot pretty-print AST with Error nodes');
}
protected function pExpr_Variable(Expr\Variable $node) {
if ($node->name instanceof Expr) {
return '${' . $this->p($node->name) . '}';

View File

@ -183,4 +183,14 @@ class PrettyPrinterTest extends CodeTestAbstract
[new DNumber(-\NAN), '\NAN'],
];
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Cannot pretty-print AST with Error nodes
*/
public function testPrettyPrintWithError() {
$stmts = [new Expr\PropertyFetch(new Expr\Variable('a'), new Expr\Error())];
$prettyPrinter = new PrettyPrinter\Standard;
$prettyPrinter->prettyPrint($stmts);
}
}