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

Promoted properties are always initialized

This commit is contained in:
Matt Brown 2020-10-02 19:44:58 -04:00 committed by Daniil Gentili
parent 67d41b8538
commit 510f1e75cd
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
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'
],
];
}
}