Skip to content
Permalink
Browse files

Fix #2204 - fix try/catch false-positive

  • Loading branch information
muglug committed Nov 9, 2019
1 parent 4e5af34 commit 7028a64440ab131ecd9ea5f763e7f6a8ebc1e630
Showing with 39 additions and 1 deletion.
  1. +1 −1 src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
  2. +38 −0 tests/UnusedVariableTest.php
@@ -96,7 +96,7 @@ public static function analyze(
$newly_assigned_var_ids
);
$possibly_referenced_var_ids = array_diff(
$possibly_referenced_var_ids = array_merge(
$context->referenced_var_ids,
$old_referenced_var_ids
);
@@ -1133,6 +1133,44 @@ function foo() : array {
echo $index;
} while (($index = $index + 1) < 10);'
],
'tryCatchInsaneRepro' => [
'<?php
function maybeThrows() : string {
return "hello";
}
function b(bool $a): void {
if (!$a) {
return;
}
$b = "";
try {
$b = maybeThrows();
echo $b;
} catch (\Exception $e) {}
echo $b;
}'
],
'tryCatchInsaneReproNoFirstBoolCheck' => [
'<?php
function maybeThrows() : string {
return "hello";
}
function b(): void {
$b = "";
try {
$b = maybeThrows();
echo $b;
} catch (\Exception $e) {}
echo $b;
}'
],
];
}

0 comments on commit 7028a64

Please sign in to comment.
You can’t perform that action at this time.