mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1713 - don’t crash when a property is unset
This commit is contained in:
parent
24a484c9dc
commit
f5e4b9b45f
@ -1004,11 +1004,12 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
||||
list(,$property_name) = explode('::$', $property_id);
|
||||
|
||||
if (!isset($method_context->vars_in_scope['$this->' . $property_name])) {
|
||||
throw new \UnexpectedValueException('$this->' . $property_name . ' should be in scope');
|
||||
$end_type = Type::getVoid();
|
||||
$end_type->initialized = false;
|
||||
} else {
|
||||
$end_type = $method_context->vars_in_scope['$this->' . $property_name];
|
||||
}
|
||||
|
||||
$end_type = $method_context->vars_in_scope['$this->' . $property_name];
|
||||
|
||||
$constructor_class_property_storage = $property_storage;
|
||||
|
||||
$error_location = $property_storage->location;
|
||||
|
@ -135,6 +135,7 @@ class PropertyFetchAnalyzer
|
||||
if ($property_id
|
||||
&& $source instanceof FunctionLikeAnalyzer
|
||||
&& $source->getMethodName() === '__construct'
|
||||
&& !$context->inside_unset
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new UninitializedProperty(
|
||||
|
@ -2374,6 +2374,18 @@ class PropertyTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'PropertyNotSetInConstructor - src' . DIRECTORY_SEPARATOR . 'somefile.php:15'
|
||||
],
|
||||
'noCrashWhenUnsettingPropertyWithoutDefaultInConstructor' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @var bool */
|
||||
private $foo;
|
||||
|
||||
public function __construct() {
|
||||
unset($this->foo);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'PropertyNotSetInConstructor'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user