From 510f1e75cd12822b58df72300598508ec814b151 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Fri, 2 Oct 2020 19:44:58 -0400 Subject: [PATCH] Promoted properties are always initialized --- .../Internal/PhpVisitor/ReflectorVisitor.php | 1 + tests/PropertyTypeTest.php | 27 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 4cf1d117d..07c15bcf8 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -2413,6 +2413,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse $class_storage->declaring_property_ids[$param_storage->name] = $fq_classlike_name; $class_storage->appearing_property_ids[$param_storage->name] = $property_id; + $class_storage->initialized_properties[$param_storage->name] = true; } } diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index d56ee25fc..88de6ca06 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -2074,7 +2074,7 @@ class PropertyTypeTest extends TestCase } }' ], - 'promotedPublicProperty' => [ + 'promotedPublicPropertyWithDefault' => [ 'foo;' ], + 'promotedPublicPropertyWitoutDefault' => [ + 'foo;' + ], 'promotedProtectedProperty' => [ ' [ - 'foo = 5; - } - }' - ], ]; } @@ -3251,13 +3251,6 @@ class PropertyTypeTest extends TestCase echo (new A)->foo;', 'error_message' => 'InaccessibleProperty', ], - 'promotedPublicPropertyWithoutSet' => [ - ' 'PropertyNotSetInConstructor' - ], ]; } }