Skip to content
Permalink
Browse files

Make assert() pure

Fixes #2113
  • Loading branch information...
muglug committed Sep 9, 2019
1 parent 56c8848 commit 21aa162d0a34a5a2480d9ce43bf005ce61efec27
Showing with 16 additions and 1 deletion.
  1. +6 −1 src/Psalm/Internal/Codebase/Functions.php
  2. +10 −0 tests/PureAnnotationTest.php
@@ -321,7 +321,7 @@ public function isCallMapFunctionPure(
'ini_set', 'sleep', 'usleep', 'register_shutdown_function',
'error_reporting', 'register_tick_function', 'unregister_tick_function',
'set_error_handler', 'user_error', 'trigger_error', 'restore_error_handler',
'date_default_timezone_set', 'assert', 'assert_options', 'setlocale',
'date_default_timezone_set', 'assert_options', 'setlocale',
'set_exception_handler', 'set_time_limit', 'putenv', 'spl_autoload_register',
'microtime', 'array_rand',
@@ -350,6 +350,11 @@ public function isCallMapFunctionPure(
return false;
}
if ($function_id === 'assert') {
$must_use = false;
return true;
}
$function_callable = \Psalm\Internal\Codebase\CallMap::getCallableFromCallMapById(
$codebase,
$function_id,
@@ -125,6 +125,16 @@ function makeA(string $s) : A {
return $a;
}'
],
'assertIsPureInProductionn' => [
'<?php
/**
* @psalm-pure
*/
function toDateTime(?DateTime $dateTime) : DateTime {
assert($dateTime instanceof DateTime);
return $dateTime;
}'
],
];
}

0 comments on commit 21aa162

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