Skip to content

Commit

Permalink
Fix #2456 - ignore UnusedFunctionCall when function asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 11, 2019
1 parent af52590 commit 4b715cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,10 @@ public static function analyze(
$context->removeAllObjectVars();
}
} elseif ($function_id
&& (($function_storage && $function_storage->pure && $must_use)
&& (($function_storage
&& $function_storage->pure
&& !$function_storage->assertions
&& $must_use)
|| ($callmap_function_pure === true && $must_use))
&& $codebase->find_unused_variables
&& !$context->inside_conditional
Expand Down
22 changes: 22 additions & 0 deletions tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,28 @@ function foo(array $arr) : array {
array_map(function($i) { echo $i;}, $a);'
],
'usedAssertFunction' => [
'<?php
/**
* @param mixed $v
* @psalm-pure
* @psalm-assert int $v
*/
function assertInt($v):void {
if (!is_int($v)) {
throw new \RuntimeException();
}
}
/**
* @psalm-pure
* @param mixed $i
*/
function takesMixed($i) : int {
assertInt($i);
return $i;
}'
],
];
}

Expand Down

0 comments on commit 4b715cd

Please sign in to comment.