Skip to content

Commit

Permalink
Define mixin declaring classname
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 27, 2020
1 parent 700b5dd commit d04e21e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public function analyze(
}
}

if ($storage->mixin) {
if ($storage->mixin && $storage->mixin_declaring_fqcln === $storage->name) {
$union = new Type\Union([$storage->mixin]);
$union->check(
$this,
Expand Down Expand Up @@ -1052,7 +1052,7 @@ public static function addContextProperties(
$class_template_params = ClassTemplateParamCollector::collect(
$codebase,
$property_class_storage,
$fq_class_name,
$codebase->classlike_storage_provider->get($fq_class_name),
null,
new Type\Atomic\TNamedObject($fq_class_name),
'$this'
Expand Down Expand Up @@ -1878,7 +1878,7 @@ public static function analyzeClassMethodReturnType(
$class_template_params = ClassTemplateParamCollector::collect(
$codebase,
$class_storage,
$original_fq_classlike_name,
$codebase->classlike_storage_provider->get($original_fq_classlike_name),
strtolower($stmt->name->name),
$this_object_type
) ?: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public static function checkReturnType(
$class_template_params = ClassTemplateParamCollector::collect(
$codebase,
$classlike_storage,
$context->self,
$codebase->classlike_storage_provider->get($context->self),
strtolower($function->name->name),
new Type\Atomic\TNamedObject($context->self),
'$this'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class ClassTemplateParamCollector
public static function collect(
Codebase $codebase,
ClassLikeStorage $class_storage,
string $static_fq_class_name,
ClassLikeStorage $static_class_storage,
string $method_name = null,
Type\Atomic $lhs_type_part = null,
string $lhs_var_id = null
) {
$static_class_storage = $codebase->classlike_storage_provider->get($static_fq_class_name);
$static_fq_class_name = $static_class_storage->name;

$non_trait_class_storage = $class_storage->is_trait
? $static_class_storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,14 @@ public static function analyze(

$fq_class_name = $codebase->classlikes->getUnAliasedName($fq_class_name);

$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);

$parent_source = $statements_analyzer->getSource();

$class_template_params = ClassTemplateParamCollector::collect(
$codebase,
$codebase->methods->getClassLikeStorageForMethod($method_id),
$fq_class_name,
$class_storage,
$method_name_lc,
$lhs_type_part,
$lhs_var_id
Expand All @@ -538,7 +540,7 @@ public static function analyze(
$class_template_params = ClassTemplateParamCollector::collect(
$codebase,
$codebase->methods->getClassLikeStorageForMethod($trait_method_id),
$fq_class_name,
$class_storage,
$method_name_lc,
$lhs_type_part,
$lhs_var_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ function (PhpParser\Node\Arg $arg) {
$found_generic_params = ClassTemplateParamCollector::collect(
$codebase,
$class_storage,
$fq_class_name,
$class_storage,
$method_name_lc,
$lhs_type_part,
null
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static function analyze(
$found_generic_params = ClassTemplateParamCollector::collect(
$codebase,
$class_storage,
$fq_class_name,
$class_storage,
strtolower($method_name),
null,
'$this'
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/Codebase/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ private function populateDataFromParentClass(
);

if ($parent_storage->mixin && !$storage->mixin) {
$storage->mixin_declaring_fqcln = $parent_storage->mixin_declaring_fqcln;
$storage->mixin = $parent_storage->mixin;
}

Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ function (array $l, array $r) : int {
|| $mixin_type instanceof Type\Atomic\TTemplateParam
) {
$storage->mixin = $mixin_type;
$storage->mixin_declaring_fqcln = $storage->name;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Storage/ClassLikeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class ClassLikeStorage
*/
public $mixin = null;

/**
* @var ?string
*/
public $mixin_declaring_fqcln = null;

/**
* @var array<string, bool>
*/
Expand Down

0 comments on commit d04e21e

Please sign in to comment.