From 2212d7c032fc1dd913210921df7ed8be32429179 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 17 Jan 2018 11:00:58 -0500 Subject: [PATCH] Reinstate $this type after parent call Fixes #444 --- .../Statements/Expression/CallChecker.php | 4 +++ tests/PropertyTypeTest.php | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Psalm/Checker/Statements/Expression/CallChecker.php b/src/Psalm/Checker/Statements/Expression/CallChecker.php index 59980aebc..f127d9fc9 100644 --- a/src/Psalm/Checker/Statements/Expression/CallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/CallChecker.php @@ -1360,6 +1360,10 @@ class CallChecker $context->include_location = $old_context_include_location; $context->self = $old_self; + + if (isset($context->vars_in_scope['$this']) && $old_self) { + $context->vars_in_scope['$this'] = Type::parseString($old_self); + } } } else { $namespace = $statements_checker->getNamespace() diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 8913676fb..b3a0c179a 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -689,6 +689,36 @@ class PropertyTypeTest extends TestCase } }', ], + 'privatePropertyAccessibleInTwoSubclasses' => [ + 'prop = 1; + } + } + class C extends A { + /** + * @var int + */ + private $prop; + + public function __construct() + { + parent::__construct(); + $this->prop = 2; + } + }', + ] ]; }