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

Merge pull request #8816 from weirdan/fix-8313

Fixes https://github.com/vimeo/psalm/issues/8313
This commit is contained in:
Bruce Weirdan 2022-12-03 01:00:23 -04:00 committed by GitHub
commit e64913c377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -524,17 +524,19 @@ class InstancePropertyAssignmentAnalyzer
}
}
$stmt_var_type = $context->vars_in_scope[$var_id]->setParentNodes(
[$var_node->id => $var_node]
);
if (isset($context->vars_in_scope[$var_id])) {
$stmt_var_type = $context->vars_in_scope[$var_id]->setParentNodes(
[$var_node->id => $var_node]
);
if ($context->vars_in_scope[$var_id]->parent_nodes) {
foreach ($context->vars_in_scope[$var_id]->parent_nodes as $parent_node) {
$data_flow_graph->addPath($parent_node, $var_node, '=', $added_taints, $removed_taints);
if ($context->vars_in_scope[$var_id]->parent_nodes) {
foreach ($context->vars_in_scope[$var_id]->parent_nodes as $parent_node) {
$data_flow_graph->addPath($parent_node, $var_node, '=', $added_taints, $removed_taints);
}
}
}
$context->vars_in_scope[$var_id] = $stmt_var_type;
$context->vars_in_scope[$var_id] = $stmt_var_type;
}
}
} else {
if ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph

View File

@ -1742,6 +1742,21 @@ class UnusedCodeTest extends TestCase
',
'error_message' => 'UnevaluatedCode',
],
'noCrashOnReadonlyStaticProp' => [
'code' => '<?php
/** @psalm-immutable */
final class C { public int $val = 2; }
final class A {
private static C $prop;
public static function f()
{
self::$prop->val = 1;
}
}
',
'error_message' => 'InaccessibleProperty',
],
];
}
}