mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #3324 - prevent crash asserting on possibly-undefined variable
This commit is contained in:
parent
65b4263315
commit
2d5c2a9dd1
@ -852,7 +852,10 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
||||
foreach ($changed_var_ids as $var_id => $_) {
|
||||
$first_appearance = $statements_analyzer->getFirstAppearance($var_id);
|
||||
|
||||
if ($first_appearance && $context->vars_in_scope[$var_id]->hasMixed()) {
|
||||
if ($first_appearance
|
||||
&& isset($context->vars_in_scope[$var_id])
|
||||
&& $context->vars_in_scope[$var_id]->hasMixed()
|
||||
) {
|
||||
if (!$context->collect_initializations
|
||||
&& !$context->collect_mutations
|
||||
&& $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath()
|
||||
|
@ -953,6 +953,19 @@ class IssetTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'assertOnPossiblyDefined' => [
|
||||
'<?php
|
||||
function crashes(): void {
|
||||
if (rand(0,1)) {
|
||||
$dt = new \DateTime;
|
||||
}
|
||||
/**
|
||||
* @psalm-suppress PossiblyUndefinedVariable
|
||||
* @psalm-suppress MixedArgument
|
||||
*/
|
||||
assert($dt);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user