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

Fix #1015 with maybe slightly hacky solution? It’s an edge case, though

This commit is contained in:
Brown 2018-10-10 11:45:56 -04:00
parent 8e73b34469
commit f56c76a8be
2 changed files with 31 additions and 1 deletions

View File

@ -302,6 +302,19 @@ class PropertyAssignmentChecker
$has_regular_setter = true;
if ($stmt->var instanceof PhpParser\Node\Expr\Variable
&& $stmt->var->name === 'this'
&& $context->self
) {
$self_property_id = $context->self . '::$' . $prop_name;
if ($self_property_id !== $property_id
&& $codebase->properties->propertyExists($self_property_id)
) {
$property_id = $self_property_id;
}
}
if (!$codebase->properties->propertyExists($property_id, $context->calling_method_id)) {
if ($stmt->var instanceof PhpParser\Node\Expr\Variable && $stmt->var->name === 'this') {
// if this is a proper error, we'll see it on the first pass
@ -361,7 +374,7 @@ class PropertyAssignmentChecker
}
$declaring_property_class = $codebase->properties->getDeclaringClassForProperty(
$lhs_type_part->value . '::$' . $prop_name
$property_id
);
$class_storage = $project_checker->classlike_storage_provider->get((string)$declaring_property_class);

View File

@ -1115,6 +1115,23 @@ class PropertyTypeTest extends TestCase
];
}'
],
'allowPrivatePropertySetAfterInstanceof' => [
'<?php
class A {
/** @var string|null */
private $foo;
public function bar() : void {
if (!$this instanceof B) {
return;
}
$this->foo = "hello";
}
}
class B extends A {}',
],
];
}