Skip to content
Permalink
Browse files

Builtin functions are assumed to be pure

  • Loading branch information...
muglug committed Aug 7, 2019
1 parent b5eb63b commit 955899ade03668df956d2ad6655042b2d71c49cf
@@ -599,7 +599,7 @@ public static function analyze(
}
if ($context->pure) {
if (!$function_storage || !$function_storage->pure) {
if ($function_storage && !$function_storage->pure) {
if (IssueBuffer::accepts(
new ImpureFunctionCall(
'Cannot call an impure function from a pure context',
@@ -368,6 +368,8 @@ public function registerFunction($function_id)
}
}
$storage->pure = true;
$storage->required_param_count = 0;
foreach ($storage->params as $i => $param) {
@@ -33,6 +33,15 @@ function filterOdd(int $i, A $a) : ?int {
return null;
}',
],
'pureFunctionCallingBuiltinFunctions' => [
'<?php
namespace Bar;
/** @psalm-pure */
function lower(string $s) : string {
return substr(strtolower($s), 0, 10);
}',
],
];
}
@@ -90,9 +99,18 @@ function filterOdd(int $i, A $a) : ?int {
'<?php
namespace Bar;
function impure() : ?string {
/** @var int */
static $i = 0;
++$i;
return $i % 2 ? "hello" : null;
}
/** @psalm-pure */
function filterOdd(array $a) : void {
extract($a);
impure();
}',
'error_message' => 'ImpureFunctionCall',
],

0 comments on commit 955899a

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