Skip to content

Commit

Permalink
Part 6. Fix mixin collisions on properties
Browse files Browse the repository at this point in the history
  • Loading branch information
issidorov committed Sep 9, 2024
1 parent 83b437a commit b206f1a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ private static function handleNonExistentProperty(
}

/**
* @param string[] $ignore_mixins
* @return array{TNamedObject, ClassLikeStorage, bool, bool, string, string}
*/
private static function handleRegularMixins(
Expand All @@ -1271,10 +1272,14 @@ private static function handleRegularMixins(
string $property_id,
PhpParser\Node\Expr\PropertyFetch $stmt,
StatementsAnalyzer $statements_analyzer,
string $fq_class_name
string $fq_class_name,
array $ignore_mixins = []
): array {
$property_exists = false;
$naive_property_exists = false;

$ignore_mixins[] = $fq_class_name;

foreach ($class_storage->namedMixins as $mixin) {
$new_property_id = $mixin->value . '::$' . $prop_name;

Expand Down Expand Up @@ -1317,6 +1322,9 @@ private static function handleRegularMixins(
}
$mixin_lhs_type_part = $mixin;
$mixin_fq_class_name = $mixin_class_storage->name;
if (in_array($mixin_fq_class_name, $ignore_mixins)) {
continue;
}

[
$new_lhs_type_part,
Expand All @@ -1336,6 +1344,7 @@ private static function handleRegularMixins(
$stmt,
$statements_analyzer,
$mixin_fq_class_name,
$ignore_mixins,
);

if ($property_exists) {
Expand Down
50 changes: 50 additions & 0 deletions tests/MixinsDeepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,56 @@ public static function __callStatic(string $name, array $arguments) {}
],
'ignored_issues' => ['MixedAssignment'],
],
'LowMixinCollision_WithProperties' => [
'code' => <<<'PHP'
<?php
/**
* @mixin Foo
*/
class Foo {
public function __get(string $name) {}
}
$foo = new Foo();
$a = $foo->notExistsProp;
PHP,
'assertions' => [
'$a' => 'mixed',
],
'ignored_issues' => ['MixedAssignment'],
],
'DeepMixinCollision_WithProperties' => [
'code' => <<<'PHP'
<?php
/**
* @mixin Baz
*/
abstract class Foo {
public function __get(string $name) {}
}
/**
* @mixin Foo
*/
abstract class Bar {
public function __get(string $name) {}
}
/**
* @mixin Bar
*/
class Baz {
public function __get(string $name) {}
}
$baz = new Baz();
$a = $baz->notExistsProp;
PHP,
'assertions' => [
'$a' => 'mixed',
],
'ignored_issues' => ['MixedAssignment'],
],
];
}
}

0 comments on commit b206f1a

Please sign in to comment.