From 1cb7dd9d7277cf630584c13a3a7d165c756de595 Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 24 Dec 2023 12:02:37 -0500 Subject: [PATCH 1/4] Initial commit, issue-10490 Reproduce failure in unit test --- tests/DeprecatedAnnotationTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/DeprecatedAnnotationTest.php b/tests/DeprecatedAnnotationTest.php index adcf30e5b..0f465bf7c 100644 --- a/tests/DeprecatedAnnotationTest.php +++ b/tests/DeprecatedAnnotationTest.php @@ -99,6 +99,24 @@ class DeprecatedAnnotationTest extends TestCase public $property; } '], + 'suppressDeprecatedClassOnTemplateType' => [ + 'code' => ' + * @psalm-suppress DeprecatedClass + */ + class TheChildClass extends TheParentClass {} + '], ]; } From 21617c702913b5556383421e72f88b9884fc6aad Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 24 Dec 2023 17:29:05 -0500 Subject: [PATCH 2/4] Include suppressed issues from the class the template is being used by --- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index a37b4b7ad..7d376caf5 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -350,7 +350,7 @@ final class ClassAnalyzer extends ClassLikeAnalyzer null, true, ), - $this->getSuppressedIssues(), + $storage->suppressed_issues + $this->getSuppressedIssues(), ); } } From a60de4bac81a1d99b976bea2a962ad67fe65093f Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 24 Dec 2023 17:50:57 -0500 Subject: [PATCH 3/4] Whitelist suppressed issue types to for template extended params --- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 2 +- src/Psalm/Storage/ClassLikeStorage.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 7d376caf5..4e6ef467b 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -350,7 +350,7 @@ final class ClassAnalyzer extends ClassLikeAnalyzer null, true, ), - $storage->suppressed_issues + $this->getSuppressedIssues(), + $storage->getSuppressedIssuesForTemplateExtendParams() + $this->getSuppressedIssues(), ); } } diff --git a/src/Psalm/Storage/ClassLikeStorage.php b/src/Psalm/Storage/ClassLikeStorage.php index f8564444a..737854d5e 100644 --- a/src/Psalm/Storage/ClassLikeStorage.php +++ b/src/Psalm/Storage/ClassLikeStorage.php @@ -10,11 +10,13 @@ use Psalm\Internal\Analyzer\ClassLikeAnalyzer; use Psalm\Internal\MethodIdentifier; use Psalm\Internal\Type\TypeAlias\ClassTypeAlias; use Psalm\Issue\CodeIssue; +use Psalm\Issue\DeprecatedClass; use Psalm\Type\Atomic\TNamedObject; use Psalm\Type\Atomic\TTemplateParam; use Psalm\Type\Union; use function array_values; +use function in_array; final class ClassLikeStorage implements HasAttributesInterface { @@ -550,4 +552,22 @@ final class ClassLikeStorage implements HasAttributesInterface return false; } + + /** + * @return array + */ + public function getSuppressedIssuesForTemplateExtendParams(): array + { + $allowed_issue_types = [ + DeprecatedClass::getIssueType(), + ]; + $suppressed_issues_for_template_extend_params = []; + foreach ($this->suppressed_issues as $offset => $suppressed_issue) { + if (!in_array($suppressed_issue, $allowed_issue_types, true)) { + continue; + } + $suppressed_issues_for_template_extend_params[$offset] = $suppressed_issue; + } + return $suppressed_issues_for_template_extend_params; + } } From c3a41d136d94a0b823e1c4c185c1bd4e0ada5650 Mon Sep 17 00:00:00 2001 From: Sam L Date: Tue, 9 Jan 2024 17:49:07 -0500 Subject: [PATCH 4/4] Bots