From f76992af885f05bd8bea92294778bfb9652778a0 Mon Sep 17 00:00:00 2001 From: Takuya Aramaki Date: Fri, 23 Jan 2026 03:39:21 +0900 Subject: [PATCH] Fix ignore comment handling for multiple traits in a single file --- src/Analyser/FileAnalyser.php | 4 +++- .../Analyser/AnalyserIntegrationTest.php | 6 ++++++ tests/PHPStan/Analyser/data/bug-13945.php | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/data/bug-13945.php diff --git a/src/Analyser/FileAnalyser.php b/src/Analyser/FileAnalyser.php index d4ae6ed984..27ccc89c85 100644 --- a/src/Analyser/FileAnalyser.php +++ b/src/Analyser/FileAnalyser.php @@ -114,7 +114,9 @@ public function analyseFile( } if ($node instanceof InTraitNode) { $traitNode = $node->getOriginalNode(); - $linesToIgnore[$scope->getFileDescription()] = $this->getLinesToIgnoreFromTokens([$traitNode]); + $fileDescription = $scope->getFileDescription(); + $linesToIgnore[$fileDescription] ??= []; + $linesToIgnore[$fileDescription] += $this->getLinesToIgnoreFromTokens([$traitNode]); } if ($scope->isInTrait()) { diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 413d8f160d..0ddaec1889 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1619,6 +1619,12 @@ public function testBug13980(): void $this->assertNoErrors($errors); } + public function testBug13945(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-13945.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return list diff --git a/tests/PHPStan/Analyser/data/bug-13945.php b/tests/PHPStan/Analyser/data/bug-13945.php new file mode 100644 index 0000000000..1fffa35587 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-13945.php @@ -0,0 +1,18 @@ +myProperty = "a"; // @phpstan-ignore property.notFound + } +} + +trait Baz { +} + +class HelloWorld +{ + use Foo; + use Baz; +}