diff --git a/src/Psalm/Checker/FileChecker.php b/src/Psalm/Checker/FileChecker.php index d0c7df758..b76c95a87 100644 --- a/src/Psalm/Checker/FileChecker.php +++ b/src/Psalm/Checker/FileChecker.php @@ -404,7 +404,7 @@ class FileChecker extends SourceChecker implements StatementsSource throw new \UnexpectedValueException('Method ' . $method_id . ' could not be checked'); } - foreach ($call_context->vars_in_scope as $var => $type) { + foreach ($call_context->vars_possibly_in_scope as $var => $_) { $this_context->vars_possibly_in_scope[$var] = true; } diff --git a/tests/MethodMutationTest.php b/tests/MethodMutationTest.php index f3cf6733a..5e7d0c002 100644 --- a/tests/MethodMutationTest.php +++ b/tests/MethodMutationTest.php @@ -102,6 +102,10 @@ class MethodMutationTest extends PHPUnit_Framework_TestCase public function barBar() : Response { $this->setUser(); + if (rand(0, 1)) { + $this->title = "hello"; + } + return new Response($this->user_viewdata); } }' @@ -116,5 +120,6 @@ class MethodMutationTest extends PHPUnit_Framework_TestCase $this->assertEquals('UserViewData', (string)$method_context->vars_in_scope['$this->user_viewdata']); $this->assertEquals('string', (string)$method_context->vars_in_scope['$this->user_viewdata->name']); + $this->assertEquals(true, (string)$method_context->vars_possibly_in_scope['$this->title']); } }