1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #4418 - improve try analysis for mixed, too

This commit is contained in:
Matt Brown 2020-10-26 09:05:48 -04:00 committed by Daniil Gentili
parent c16d779bca
commit 870d07ba51
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 28 additions and 8 deletions

View File

@ -384,10 +384,6 @@ class TryAnalyzer
$possibly_referenced_var_ids
);
if ($codebase->find_unused_variables && $catch_actions[$i] !== [ScopeAnalyzer::ACTION_END]) {
// something
}
if ($catch_context->collect_exceptions) {
$context->mergeExceptions($catch_context);
}

View File

@ -445,10 +445,6 @@ abstract class Type
$combined_type->initialized = false;
}
if ($type_1->possibly_undefined_from_try || $type_2->possibly_undefined_from_try) {
$combined_type->possibly_undefined_from_try = true;
}
if ($type_1->from_docblock || $type_2->from_docblock) {
$combined_type->from_docblock = true;
}
@ -482,6 +478,10 @@ abstract class Type
$combined_type->possibly_undefined = true;
}
if ($type_1->possibly_undefined_from_try || $type_2->possibly_undefined_from_try) {
$combined_type->possibly_undefined_from_try = true;
}
if ($type_1->parent_nodes || $type_2->parent_nodes) {
$combined_type->parent_nodes = $type_1->parent_nodes + $type_2->parent_nodes;
}

View File

@ -441,6 +441,30 @@ class TryCatchTest extends TestCase
return $foo;
}'
],
'mixedNotUndefinedAfterTry' => [
'<?php
/**
* @return array<int, mixed>
* @psalm-suppress MixedAssignment
*/
function fetchFromCache(mixed $m)
{
$data = [];
try {
$value = $m;
} catch (Throwable $e) {
$value = $m;
}
$data[] = $value;
return $data;
}',
[],
[],
'8.0'
],
];
}