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

Report use of impure closures

This commit is contained in:
Brown 2020-08-28 13:01:07 -04:00 committed by Daniil Gentili
parent 2375a3b2cd
commit ca1b29b1dd
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 4 additions and 3 deletions

View File

@ -675,7 +675,7 @@ class TypeParser
}, },
$parse_tree->children $parse_tree->children
); );
$pure = strpos($parse_tree->value, 'pure-') === 0; $pure = strpos($parse_tree->value, 'pure-') === 0 ? true : null;
if (in_array(strtolower($parse_tree->value), ['closure', '\closure'], true)) { if (in_array(strtolower($parse_tree->value), ['closure', '\closure'], true)) {
return new TFn('Closure', $params, null, $pure); return new TFn('Closure', $params, null, $pure);

View File

@ -43,7 +43,7 @@ trait CallableTrait
$value = 'callable', $value = 'callable',
array $params = null, array $params = null,
Union $return_type = null, Union $return_type = null,
bool $is_pure = false ?bool $is_pure = null
) { ) {
$this->value = $value; $this->value = $value;
$this->params = $params; $this->params = $params;
@ -187,7 +187,8 @@ trait CallableTrait
. $this->return_type->getId() . ($return_type_multiple ? ')' : ''); . $this->return_type->getId() . ($return_type_multiple ? ')' : '');
} }
return ($this->is_pure ? 'pure-' : '') . $this->value . $param_string . $return_type_string; return ($this->is_pure ? 'pure-' : ($this->is_pure === null ? '' : 'impure-'))
. $this->value . $param_string . $return_type_string;
} }
public function __toString() public function __toString()