From 36fdc6fdc0619a2ea27211d2a4d6b1ee4cdb5d85 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 10 Sep 2022 15:13:55 +0200 Subject: [PATCH] Check that all preprocessor conditions are terminated --- build/gen_stub.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 985ba59b766..1cc3dc74b50 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3657,6 +3657,8 @@ function getFileDocComment(array $stmts): ?DocComment { function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstract $prettyPrinter) { $conds = []; foreach ($stmts as $stmt) { + $cond = handlePreprocessorConditions($conds, $stmt); + if ($stmt instanceof Stmt\Nop) { continue; } @@ -3666,8 +3668,6 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac continue; } - $cond = handlePreprocessorConditions($conds, $stmt); - if ($stmt instanceof Stmt\Const_) { foreach ($stmt->consts as $const) { $fileInfo->constInfos[] = parseConstLike( @@ -3775,6 +3775,9 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac throw new Exception("Unexpected node {$stmt->getType()}"); } + if (!empty($conds)) { + throw new Exception("Unterminated preprocessor conditions"); + } } function parseStubFile(string $code): FileInfo {