1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #4615 - ensure promoted properties are not treated as uninitialized

This commit is contained in:
Matt Brown 2020-11-22 00:32:02 -05:00 committed by Daniil Gentili
parent 2fff4eb5c1
commit dc9a2a48e9
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 8 additions and 1 deletions

View File

@ -1033,6 +1033,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$property_type = clone $property_storage->type;
if (!$property_type->isMixed()
&& !$property_storage->is_promoted
&& !$property_storage->has_default
&& !($property_type->isNullable() && $property_type->from_docblock)
) {
@ -1041,7 +1042,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
} else {
$property_type = Type::getMixed();
if (!$property_storage->has_default) {
if (!$property_storage->has_default && !$property_storage->is_promoted) {
$property_type->initialized = false;
}
}

View File

@ -728,6 +728,7 @@ class FunctionLikeNodeScanner
$property_storage->stmt_location = new CodeLocation($this->file_scanner, $param);
$property_storage->has_default = $param->default ? true : false;
$param_storage->promoted_property = true;
$property_storage->is_promoted = true;
$property_id = $fq_classlike_name . '::$' . $param_storage->name;

View File

@ -86,6 +86,11 @@ class PropertyStorage
*/
public $getter_method = null;
/**
* @var bool
*/
public $is_promoted = false;
/**
* @var list<AttributeStorage>
*/