1
0
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:
Brown 2020-05-08 14:21:10 -04:00
parent 65b4263315
commit 2d5c2a9dd1
2 changed files with 17 additions and 1 deletions

View File

@ -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()

View File

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