Skip to content

Commit

Permalink
Fix #4540 - use correct method when simulating property setting
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 13, 2020
1 parent 556fb12 commit 5a62dc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function analyze(
$file_analyzer = $statements_analyzer->getFileAnalyzer();

if ($context->collect_mutations) {
$file_analyzer->getMethodMutations($method_id, $context);
$file_analyzer->getMethodMutations($appearing_method_id, $context);
} else {
// collecting initializations
$local_vars_in_scope = [];
Expand All @@ -98,14 +98,14 @@ public static function analyze(
}
}

if (!isset($context->initialized_methods[(string) $method_id])) {
if (!isset($context->initialized_methods[(string) $appearing_method_id])) {
if ($context->initialized_methods === null) {
$context->initialized_methods = [];
}

$context->initialized_methods[(string) $method_id] = true;
$context->initialized_methods[(string) $appearing_method_id] = true;

$file_analyzer->getMethodMutations($method_id, $context);
$file_analyzer->getMethodMutations($appearing_method_id, $context);

foreach ($local_vars_in_scope as $var => $type) {
$context->vars_in_scope[$var] = $type;
Expand Down
21 changes: 21 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,27 @@ public function bar() : int {
}
}'
],
'skipConstructor' => [
'<?php
class A {
protected string $s;
public function __construct() {
$this->s = "hello";
}
}
class B extends A {}
class C extends B {
public function __construct()
{
parent::__construct();
echo $this->s;
}
}'
],
];
}

Expand Down

0 comments on commit 5a62dc5

Please sign in to comment.