1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Promoted properties are always initialized

This commit is contained in:
Matt Brown 2020-10-02 19:44:58 -04:00
parent 5bcd1bbb75
commit 2cd306b75c
2 changed files with 11 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -2074,7 +2074,7 @@ class PropertyTypeTest extends TestCase
}
}'
],
'promotedPublicProperty' => [
'promotedPublicPropertyWithDefault' => [
'<?php
class A {
public function __construct(public int $foo = 5) {}
@ -2082,10 +2082,18 @@ class PropertyTypeTest extends TestCase
echo (new A)->foo;'
],
'promotedPublicPropertyWitoutDefault' => [
'<?php
class A {
public function __construct(public int $foo) {}
}
echo (new A(5))->foo;'
],
'promotedProtectedProperty' => [
'<?php
class A {
public function __construct(protected int $foo = 5) {}
public function __construct(protected int $foo) {}
}
class AChild extends A {
@ -2094,14 +2102,6 @@ class PropertyTypeTest extends TestCase
}
}'
],
'setPublicProperty' => [
'<?php
class A {
public function __construct(public int $foo) {
$this->foo = 5;
}
}'
],
];
}
@ -3251,13 +3251,6 @@ class PropertyTypeTest extends TestCase
echo (new A)->foo;',
'error_message' => 'InaccessibleProperty',
],
'promotedPublicPropertyWithoutSet' => [
'<?php
class A {
public function __construct(public int $foo) {}
}',
'error_message' => 'PropertyNotSetInConstructor'
],
];
}
}