1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Always remove callable type

This commit is contained in:
Matthew Brown 2019-02-11 01:44:07 -05:00
parent e5360a6faa
commit 7fdc226ac5
2 changed files with 23 additions and 0 deletions

View File

@ -1748,6 +1748,8 @@ class Reconciler
} }
if ($new_var_type === 'callable') { if ($new_var_type === 'callable') {
$existing_var_type->removeType('callable');
foreach ($existing_var_atomic_types as $atomic_key => $type) { foreach ($existing_var_atomic_types as $atomic_key => $type) {
if ($type instanceof Type\Atomic\TLiteralString if ($type instanceof Type\Atomic\TLiteralString
&& \Psalm\Internal\Codebase\CallMap::inCallMap($type->value) && \Psalm\Internal\Codebase\CallMap::inCallMap($type->value)

View File

@ -1230,6 +1230,27 @@ class TypeReconciliationTest extends TestCase
echo $a; echo $a;
}', }',
], ],
'removeCallableWithAssertion' => [
'<?php
/**
* @param mixed $p
* @psalm-assert !callable $p
* @throws TypeError
*/
function assertIsNotCallable($p): void { if (!is_callable($p)) throw new TypeError; }
/** @return callable|float */
function f() { return rand(0,1) ? "f" : 1.1; }
$a = f();
assert(!is_callable($a));
$b = f();
assertIsNotCallable($b);
atan($a);
atan($b);',
],
'PHP71-removeNonCallable' => [ 'PHP71-removeNonCallable' => [
'<?php '<?php
$f = rand(0, 1) ? "strlen" : 1.1; $f = rand(0, 1) ? "strlen" : 1.1;