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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
) {
Expand All @@ -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))
) {
Expand All @@ -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))
) {
Expand Down
4 changes: 4 additions & 0 deletions tests/MixinAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct() {
$this->b = new B();
}
public function c(string $s) : void {}
/**
* @param array<mixed> $arguments
* @return mixed
Expand All @@ -67,6 +69,8 @@ class B {
public function b(): void {
echo "b";
}
public function c(int $s) : void {}
}
$a = new A();
Expand Down

0 comments on commit 07aaa3f

Please sign in to comment.