Skip to content
Permalink
Browse files

Don’t complain about method mismatches for @mixin

  • Loading branch information
muglug committed Jan 6, 2020
1 parent 63dea52 commit 07aaa3f99d2062ee1a35d013eb91cb3efbcedfaa
Showing with 16 additions and 7 deletions.
  1. +12 −7 src/Psalm/Internal/Codebase/Populator.php
  2. +4 −0 tests/MixinAnnotationTest.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))
) {
@@ -53,6 +53,8 @@ public function __construct() {
$this->b = new B();
}
public function c(string $s) : void {}
/**
* @param array<mixed> $arguments
* @return mixed
@@ -67,6 +69,8 @@ class B {
public function b(): void {
echo "b";
}
public function c(int $s) : void {}
}
$a = new A();

0 comments on commit 07aaa3f

Please sign in to comment.
You can’t perform that action at this time.