mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #7583 from AndrolGenhald/bugfix/7580
This commit is contained in:
commit
333f148d1b
@ -929,6 +929,12 @@ class AssignmentAnalyzer
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($context->vars_in_scope[$rhs_var_id])) {
|
||||
// Sometimes the $rhs_var_id isn't set in $vars_in_scope, for example if it's an unknown array offset.
|
||||
$context->vars_in_scope[$rhs_var_id] = $statements_analyzer->node_data->getType($stmt->expr)
|
||||
?? Type::getMixed();
|
||||
}
|
||||
|
||||
if (isset($context->references_in_scope[$lhs_var_id])) {
|
||||
// Decrement old referenced variable's reference count
|
||||
$reference_count = &$context->referenced_counts[$context->references_in_scope[$lhs_var_id]];
|
||||
|
@ -218,6 +218,35 @@ class ReferenceTest extends TestCase
|
||||
}
|
||||
',
|
||||
],
|
||||
'dontCrashOnReferenceToMixedVariableArrayOffset' => [
|
||||
'code' => '<?php
|
||||
function func(&$a): void
|
||||
{
|
||||
$_ = &$a["f"];
|
||||
}
|
||||
',
|
||||
'assertions' => [],
|
||||
'ignored_issues' => ['MixedArrayAccess', 'MissingParamType'],
|
||||
],
|
||||
'dontCrashOnReferenceToArrayUnknownOffset' => [
|
||||
'code' => '<?php
|
||||
function func(array &$a): void
|
||||
{
|
||||
$_ = &$a["f"];
|
||||
}
|
||||
',
|
||||
'assertions' => [],
|
||||
],
|
||||
'dontCrashOnReferenceToArrayMixedOffset' => [
|
||||
'code' => '<?php
|
||||
/** @param array{f: mixed} $a */
|
||||
function func(array &$a): void
|
||||
{
|
||||
$_ = &$a["f"];
|
||||
}
|
||||
',
|
||||
'assertions' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user