Skip to content

Commit

Permalink
Don’t complain about method mismatches for @mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 6, 2020
1 parent 63dea52 commit 07aaa3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Psalm/Internal/Codebase/Populator.php
Expand Up @@ -444,8 +444,8 @@ private function populateDataFromMixin(


$this->populateClassLikeStorage($mixin_storage, $dependent_classlikes); $this->populateClassLikeStorage($mixin_storage, $dependent_classlikes);


$this->inheritMethodsFromParent($storage, $mixin_storage); $this->inheritMethodsFromParent($storage, $mixin_storage, true);
$this->inheritPropertiesFromParent($storage, $mixin_storage, false); $this->inheritPropertiesFromParent($storage, $mixin_storage, true);
} }


private static function extendType( private static function extendType(
Expand Down Expand Up @@ -1043,7 +1043,8 @@ private function convertPhpStormGenericToPsalmGeneric(Type\Union $candidate, $is
*/ */
protected function inheritMethodsFromParent( protected function inheritMethodsFromParent(
ClassLikeStorage $storage, ClassLikeStorage $storage,
ClassLikeStorage $parent_storage ClassLikeStorage $parent_storage,
bool $is_mixin = false
) { ) {
$fq_class_name = $storage->name; $fq_class_name = $storage->name;


Expand Down Expand Up @@ -1090,6 +1091,10 @@ protected function inheritMethodsFromParent(


// register where they're declared // register where they're declared
foreach ($parent_storage->inheritable_method_ids as $method_name => $declaring_method_id) { 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 ($method_name !== '__construct') {
if ($parent_storage->is_trait) { if ($parent_storage->is_trait) {
$declaring_class = explode('::', $declaring_method_id)[0]; $declaring_class = explode('::', $declaring_method_id)[0];
Expand Down Expand Up @@ -1152,7 +1157,7 @@ protected function inheritMethodsFromParent(
private function inheritPropertiesFromParent( private function inheritPropertiesFromParent(
ClassLikeStorage $storage, ClassLikeStorage $storage,
ClassLikeStorage $parent_storage, ClassLikeStorage $parent_storage,
bool $include_protected = true bool $is_mixin = false
) { ) {
// register where they appear (can never be in a trait) // register where they appear (can never be in a trait)
foreach ($parent_storage->appearing_property_ids as $property_name => $appearing_property_id) { foreach ($parent_storage->appearing_property_ids as $property_name => $appearing_property_id) {
Expand All @@ -1163,7 +1168,7 @@ private function inheritPropertiesFromParent(
if (!$parent_storage->is_trait if (!$parent_storage->is_trait
&& isset($parent_storage->properties[$property_name]) && isset($parent_storage->properties[$property_name])
&& ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|| (!$include_protected || ($is_mixin
&& $parent_storage->properties[$property_name]->visibility && $parent_storage->properties[$property_name]->visibility
=== ClassLikeAnalyzer::VISIBILITY_PROTECTED)) === ClassLikeAnalyzer::VISIBILITY_PROTECTED))
) { ) {
Expand All @@ -1185,7 +1190,7 @@ private function inheritPropertiesFromParent(
if (!$parent_storage->is_trait if (!$parent_storage->is_trait
&& isset($parent_storage->properties[$property_name]) && isset($parent_storage->properties[$property_name])
&& ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|| (!$include_protected || ($is_mixin
&& $parent_storage->properties[$property_name]->visibility && $parent_storage->properties[$property_name]->visibility
=== ClassLikeAnalyzer::VISIBILITY_PROTECTED)) === ClassLikeAnalyzer::VISIBILITY_PROTECTED))
) { ) {
Expand All @@ -1200,7 +1205,7 @@ private function inheritPropertiesFromParent(
if (!$parent_storage->is_trait if (!$parent_storage->is_trait
&& isset($parent_storage->properties[$property_name]) && isset($parent_storage->properties[$property_name])
&& ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE && ($parent_storage->properties[$property_name]->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|| (!$include_protected || ($is_mixin
&& $parent_storage->properties[$property_name]->visibility && $parent_storage->properties[$property_name]->visibility
=== ClassLikeAnalyzer::VISIBILITY_PROTECTED)) === ClassLikeAnalyzer::VISIBILITY_PROTECTED))
) { ) {
Expand Down
4 changes: 4 additions & 0 deletions tests/MixinAnnotationTest.php
Expand Up @@ -53,6 +53,8 @@ public function __construct() {
$this->b = new B(); $this->b = new B();
} }
public function c(string $s) : void {}
/** /**
* @param array<mixed> $arguments * @param array<mixed> $arguments
* @return mixed * @return mixed
Expand All @@ -67,6 +69,8 @@ class B {
public function b(): void { public function b(): void {
echo "b"; echo "b";
} }
public function c(int $s) : void {}
} }
$a = new A(); $a = new A();
Expand Down

0 comments on commit 07aaa3f

Please sign in to comment.