1
0
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:
Bruce Weirdan 2022-02-04 16:41:03 +02:00 committed by GitHub
commit 333f148d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -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]];

View File

@ -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' => [],
],
];
}