From 257ebfd2057f170003a84c3878274d5c182d4fd0 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 16 Jan 2020 22:36:30 -0500 Subject: [PATCH] Improve trait method mismatch failure rules --- .../Internal/Analyzer/MethodAnalyzer.php | 4 +++ tests/MethodSignatureTest.php | 34 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php index 865ea2e50..ce7803815 100644 --- a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php @@ -594,6 +594,8 @@ class MethodAnalyzer extends FunctionLikeAnalyzer if (!$is_contained_by) { if ($guide_classlike_storage->is_trait === $implementer_classlike_storage->is_trait + || !in_array($guide_classlike_storage->name, $implementer_classlike_storage->used_traits) + || $implementer_method_storage->defining_fqcln !== $implementer_classlike_storage->name || (!$implementer_method_storage->abstract && !$guide_method_storage->abstract) ) { @@ -912,6 +914,8 @@ class MethodAnalyzer extends FunctionLikeAnalyzer ); if (!$is_contained_by) { if ($guide_classlike_storage->is_trait === $implementer_classlike_storage->is_trait + || !in_array($guide_classlike_storage->name, $implementer_classlike_storage->used_traits) + || $implementer_method_storage->defining_fqcln !== $implementer_classlike_storage->name || (!$implementer_method_storage->abstract && !$guide_method_storage->abstract) ) { diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index f8ed4b218..0491fffbd 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -885,7 +885,7 @@ class MethodSignatureTest extends TestCase class B extends A { use T; }', - 'error_message' => 'TraitMethodSignatureMismatch', + 'error_message' => 'MethodSignatureMismatch', ], 'abstractTraitMethodWithDifferentReturnType' => [ ' 'TraitMethodSignatureMismatch', + 'error_message' => 'MethodSignatureMismatch', ], 'abstractTraitMethodWithDifferentParamType' => [ ' 'InvalidReturnType', 2 => ['InvalidParent'], ], + 'regularMethodMismatchFromParentUse' => [ + ' 'MethodSignatureMismatch', + ], + 'regularMethodMismatchFromChildUse' => [ + ' 'MethodSignatureMismatch', + ], ]; } }