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:
parent
e5360a6faa
commit
7fdc226ac5
@ -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)
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user