Skip to content

Commit

Permalink
Part 6. Fix mixin collisions on static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
issidorov committed Aug 26, 2024
1 parent 9cb09d9 commit 94e7dc3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ private static function checkPseudoMethod(

/**
* @param lowercase-string $method_name_lc
* @param string[] $ignore_mixins
*/
private static function handleRegularMixins(
ClassLikeStorage $class_storage,
Expand All @@ -934,11 +935,15 @@ private static function handleRegularMixins(
Context $context,
PhpParser\Node\Identifier $stmt_name,
StatementsAnalyzer $statements_analyzer,
string $fq_class_name
string $fq_class_name,
array $ignore_mixins = []
): ?Union {
if ($class_storage->mixin_declaring_fqcln === null) {
return null;
}

$ignore_mixins[] = $fq_class_name;

foreach ($class_storage->namedMixins as $mixin) {
$new_method_id = new MethodIdentifier(
$mixin->value,
Expand Down Expand Up @@ -1023,6 +1028,9 @@ private static function handleRegularMixins(
}
$mixin_class_storage = $codebase->classlike_storage_provider->get($mixin->value);
$mixin_fq_class_name = $mixin_class_storage->name;
if (in_array($mixin_fq_class_name, $ignore_mixins)) {
continue;
}
$new_lhs_type = self::handleRegularMixins(
$mixin_class_storage,
$lhs_type_part,
Expand All @@ -1032,6 +1040,7 @@ private static function handleRegularMixins(
$stmt_name,
$statements_analyzer,
$mixin_fq_class_name,
$ignore_mixins,
);
if ($new_lhs_type) {
return $new_lhs_type;
Expand Down
48 changes: 48 additions & 0 deletions tests/MixinsDeepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,54 @@ public function __call(string $name, array $arguments) {}
],
'ignored_issues' => ['MixedAssignment'],
],
'LowMixinCollision_WithStaticMethods' => [
'code' => <<<'PHP'
<?php
/**
* @mixin Foo
*/
class Foo {
public static function __callStatic(string $name, array $arguments) {}
}
$a = Foo::notExistsMethod();
PHP,
'assertions' => [
'$a' => 'mixed',
],
'ignored_issues' => ['MixedAssignment'],
],
'DeepMixinCollision_WithStaticMethods' => [
'code' => <<<'PHP'
<?php
/**
* @mixin Baz
*/
abstract class Foo {
public static function __callStatic(string $name, array $arguments) {}
}
/**
* @mixin Foo
*/
abstract class Bar {
public static function __callStatic(string $name, array $arguments) {}
}
/**
* @mixin Bar
*/
class Baz {
public static function __callStatic(string $name, array $arguments) {}
}
$a = Baz::notExistsMethod();
PHP,
'assertions' => [
'$a' => 'mixed',
],
'ignored_issues' => ['MixedAssignment'],
],
];
}
}

0 comments on commit 94e7dc3

Please sign in to comment.