1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #4802 - don’t clone context when analysing coalesce

This commit is contained in:
Matt Brown 2020-12-07 14:30:48 -05:00
parent d406d5b112
commit f5dd6e76f8
2 changed files with 10 additions and 1 deletions

View File

@ -68,7 +68,7 @@ class CoalesceAnalyzer
$statements_analyzer->node_data = clone $statements_analyzer->node_data;
ExpressionAnalyzer::analyze($statements_analyzer, $ternary, clone $context);
ExpressionAnalyzer::analyze($statements_analyzer, $ternary, $context);
$ternary_type = $statements_analyzer->node_data->getType($ternary) ?: Type::getMixed();

View File

@ -997,6 +997,15 @@ class IssetTest extends \Psalm\Tests\TestCase
echo $arr["a"]["b"] ?? 0;
}'
],
'coalescePreserveContext' => [
'<?php
function foo(array $test) : void {
/** @psalm-suppress MixedArgument */
echo $test[0] ?? ( $test[0] = 1 );
/** @psalm-suppress MixedArgument */
echo $test[0];
}'
],
];
}