mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix crash when assigning reference to unknown array offset.
This commit is contained in:
parent
c5722dd5e8
commit
5b469ca577
@ -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