Fix emulative lexer with default error handler

If no error handler is provided, explicitly create one, so we don't
end up calling handleError() on null.
This commit is contained in:
Nikita Popov 2023-05-20 22:26:53 +02:00
parent c23976a299
commit fb2c3ac97c
2 changed files with 12 additions and 0 deletions

View File

@ -85,6 +85,10 @@ class Emulative extends Lexer {
return;
}
if ($errorHandler === null) {
$errorHandler = new ErrorHandler\Throwing();
}
$this->patches = [];
foreach ($emulators as $emulator) {
$code = $emulator->preprocessCode($code, $this->patches);

View File

@ -47,6 +47,14 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
];
}
public function testDefaultErrorHandler() {
$this->expectException(Error::class);
$this->expectExceptionMessage('Unterminated comment on line 1');
$lexer = $this->getLexer();
$lexer->startLexing("<?php readonly /*");
$lexer->getNextToken();
}
/**
* @dataProvider provideTestLex
*/