mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Promoted properties are always initialized
This commit is contained in:
parent
67d41b8538
commit
510f1e75cd
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user