From a3d8f57ef44c485b28d9b8cdba2599a29c50472f Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 23 Jul 2026 21:38:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=B0=BE=E9=83=A8=E6=9C=89?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=AF=BC=E8=87=B4=E7=BC=96=E8=AF=91=E4=B8=8D?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Preprocessor.php | 2 ++ src/Translator.php | 2 ++ .../namespace/namespace-ending-comment.phpt | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/compiler/namespace/namespace-ending-comment.phpt diff --git a/src/Preprocessor.php b/src/Preprocessor.php index 2d311e00..9e0d5d11 100644 --- a/src/Preprocessor.php +++ b/src/Preprocessor.php @@ -321,6 +321,8 @@ class Preprocessor extends CompilerBase case 'Stmt_Interface': $this->parseInterface($v2); break; + case 'Stmt_Nop': + break; default: $this->foundStrayCode($v2); break; diff --git a/src/Translator.php b/src/Translator.php index 14916aec..402568ea 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -2514,6 +2514,8 @@ CODE; case 'Stmt_Interface': $this->validateInterfaceOverrideAttributes($v2); break; + case 'Stmt_Nop': + break; default: abort($v2); break; diff --git a/tests/compiler/namespace/namespace-ending-comment.phpt b/tests/compiler/namespace/namespace-ending-comment.phpt new file mode 100644 index 00000000..fa0f3da0 --- /dev/null +++ b/tests/compiler/namespace/namespace-ending-comment.phpt @@ -0,0 +1,22 @@ +--TEST-- +A namespace block ending with a comment must not be treated as stray code +--FILE-- + +--EXPECT-- +string(4) "done" -- 2.34.1 From eadac69dcdcea7ff9741ac2992bfae0ba2aa0c77 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 24 Jul 2026 16:59:31 +0800 Subject: [PATCH 2/2] test(compiler): cover namespace trailing comment variants --- .../namespace_ending_comment_unbracketed.php | 14 ++++++++++++++ phpunit/src/PreprocessorTest.php | 19 +++++++++++++++++++ .../namespace/namespace-ending-comment.phpt | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php diff --git a/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php b/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php new file mode 100644 index 00000000..7ad8b333 --- /dev/null +++ b/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php @@ -0,0 +1,14 @@ +assertSame('App\\VERSION', $constants['_const_var_App__VERSION']->name); } + public function testNamespaceEndingCommentWithUnbracketedSyntaxIsIgnored(): void + { + global $translator; + $file = __DIR__ . '/../code/preprocessor/namespace_ending_comment_unbracketed.php'; + $previousTranslator = $translator ?? null; + $translator = $this->compiler; + + try { + $this->compiler->addFiles([$file]); + $this->compiler->prepareFile($file); + $this->compiler->convertFile($file); + } finally { + $translator = $previousTranslator; + } + + $constants = $this->getProperty('constants'); + $this->assertArrayHasKey('_const_var_NamespaceEndingComment__VALUE', $constants); + } + public function testSortFilesUsesImplementsAndTraitDependencies(): void { $classFile = realpath(__DIR__ . '/../code/preprocessor/deps_class_implements.php'); diff --git a/tests/compiler/namespace/namespace-ending-comment.phpt b/tests/compiler/namespace/namespace-ending-comment.phpt index fa0f3da0..e937a711 100644 --- a/tests/compiler/namespace/namespace-ending-comment.phpt +++ b/tests/compiler/namespace/namespace-ending-comment.phpt @@ -6,7 +6,7 @@ A namespace block ending with a comment must not be treated as stray code declare(strict_types=1); namespace Test { - // test + /* named namespace trailing block comment */ } namespace { @@ -15,7 +15,7 @@ namespace { var_dump('done'); } - // test1 + // global namespace trailing line comment } ?> --EXPECT-- -- 2.34.1