From 07aaa3f99d2062ee1a35d013eb91cb3efbcedfaa Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 6 Jan 2020 18:04:21 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20complain=20about=20method=20mis?= =?UTF-8?q?matches=20for=20@mixin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Psalm/Internal/Codebase/Populator.php | 19 ++++++++++++------- tests/MixinAnnotationTest.php | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index e50fd021b44..9b40e68bf6f 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -444,8 +444,8 @@ private function populateDataFromMixin( $this->populateClassLikeStorage($mixin_storage, $dependent_classlikes); - $this->inheritMethodsFromParent($storage, $mixin_storage); - $this->inheritPropertiesFromParent($storage, $mixin_storage, false); + $this->inheritMethodsFromParent($storage, $mixin_storage, true); + $this->inheritPropertiesFromParent($storage, $mixin_storage, true); } private static function extendType( @@ -1043,7 +1043,8 @@ private function convertPhpStormGenericToPsalmGeneric(Type\Union $candidate, $is */ protected function inheritMethodsFromParent( ClassLikeStorage $storage, - ClassLikeStorage $parent_storage + ClassLikeStorage $parent_storage, + bool $is_mixin = false ) { $fq_class_name = $storage->name; @@ -1090,6 +1091,10 @@ protected function inheritMethodsFromParent( // register where they're declared foreach ($parent_storage->inheritable_method_ids as $method_name => $declaring_method_id) { + if ($is_mixin && isset($storage->declaring_method_ids[$method_name])) { + continue; + } + if ($method_name !== '__construct') { if ($parent_storage->is_trait) { $declaring_class = explode('::', $declaring_method_id)[0]; @@ -1152,7 +1157,7 @@ protected function inheritMethodsFromParent( private function inheritPropertiesFromParent( ClassLikeStorage $storage, ClassLikeStorage $parent_storage, - bool $include_protected = true + bool $is_mixin = false ) { // register where they appear (can never be in a trait) foreach ($parent_storage->appearing_property_ids as $property_name => $appearing_property_id) { @@ -1163,7 +1168,7 @@ private function inheritPropertiesFromParent( if (!$parent_storage->is_trait && isset($parent_storage->properties[$property_name]) && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE - || (!$include_protected + || ($is_mixin && $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED)) ) { @@ -1185,7 +1190,7 @@ private function inheritPropertiesFromParent( if (!$parent_storage->is_trait && isset($parent_storage->properties[$property_name]) && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE - || (!$include_protected + || ($is_mixin && $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED)) ) { @@ -1200,7 +1205,7 @@ private function inheritPropertiesFromParent( if (!$parent_storage->is_trait && isset($parent_storage->properties[$property_name]) && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE - || (!$include_protected + || ($is_mixin && $parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED)) ) { diff --git a/tests/MixinAnnotationTest.php b/tests/MixinAnnotationTest.php index ecc35e94fff..249ffb9f9cb 100644 --- a/tests/MixinAnnotationTest.php +++ b/tests/MixinAnnotationTest.php @@ -53,6 +53,8 @@ public function __construct() { $this->b = new B(); } + public function c(string $s) : void {} + /** * @param array $arguments * @return mixed @@ -67,6 +69,8 @@ class B { public function b(): void { echo "b"; } + + public function c(int $s) : void {} } $a = new A();