pure-callablepure-callable resolves to CallableType(isPure: yes)| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | Unrecognized | phpdoc_advanced_fallback_pure_callable.php:27: Saw a token Phan may have failed to parse after '* @return pure-callable': after pure, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_pure_callable.php:29: Return type of returnsPureCallable() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure [PhanUndeclaredTypeReturnType] phpdoc_advanced_fallback_pure_callable.php:31: Returning (fn) of type Closure(int):int but returnsPureCallable() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal] phpdoc_advanced_fallback_pure_callable.php:39: Saw possibly unextractable annotation for a fragment of comment '* @param pure-callable $value': after pure, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_pure_callable.php:39: Saw a token Phan may have failed to parse after '* @param pure-callable $value': after pure, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_pure_callable.php:41: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_pure_callable.php:46: Argument 1 ($value) is returnsPureCallable() of type \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure but \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsCallable() takes callable defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:34 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_pure_callable.php:49: Argument 1 ($value) is (fn) of type Closure(int):int but \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable() takes \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:41 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_pure_callable.php:55: Argument 1 ($value) is $impureClosure of type Closure():void but \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable() takes \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:41 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_pure_callable.php:58: Argument 1 ($value) is impureFunction(...) of type Closure():int but \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable() takes \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:41 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_pure_callable.php:61: Argument 1 ($value) is 1 of type int (value: 1) but \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable() takes \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:41 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 31: Expected valid value to be accepted, got ["Returning (fn) of type Closure(int):int but returnsPureCallable() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\pure (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"] Line 46: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsPureCallable() of type \\Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\pure but \\Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\acceptsCallable() takes callable defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:34 [PhanTypeMismatchArgument]"] Line 49: Expected valid value to be accepted, got ["Argument 1 ($value) is (fn) of type Closure(int):int but \\Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\acceptsPureCallable() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\pure (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_pure_callable.php:41 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"] |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced reported Lv.5+ | phpdoc_advanced_fallback_pure_callable.php:55: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): void given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_pure_callable.php:58: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): int given. [identifier=argument.type] [reported-from-level=7] phpdoc_advanced_fallback_pure_callable.php:61: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, 1 given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_pure_callable.php:55: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): void given. [identifier=argument.type] phpdoc_advanced_fallback_pure_callable.php:58: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): int given. [identifier=argument.type] phpdoc_advanced_fallback_pure_callable.php:61: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, 1 given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced (pzoom≠) | phpdoc_advanced_fallback_pure_callable.php:55: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but impure-Closure():void provided [InvalidArgument] phpdoc_advanced_fallback_pure_callable.php:58: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but impure-Closure():int provided [InvalidArgument] phpdoc_advanced_fallback_pure_callable.php:61: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but 1 provided [InvalidArgument] pzoom (Psalm port)phpdoc_advanced_fallback_pure_callable.php:61: Argument 1 of acceptsPureCallable expects pure-callable, but 1 provided [InvalidArgument]
|
| mago | 1.46.0mago 1.46.0 | Incidental (3/3) | phpdoc_advanced_fallback_pure_callable.php:31: Invalid return type for function `Conformance\Tests\PhpdocAdvancedFallbackPureCallable\returnsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(int): int)`. [invalid-return-statement] phpdoc_advanced_fallback_pure_callable.php:49: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(int): int)`. [invalid-argument] phpdoc_advanced_fallback_pure_callable.php:55: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(): void)`. [invalid-argument] phpdoc_advanced_fallback_pure_callable.php:58: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(): int)`. [invalid-argument] phpdoc_advanced_fallback_pure_callable.php:61: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `int(1)`. [invalid-argument]
Expectation diffLine 31: Expected valid value to be accepted, got ["Invalid return type for function `Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\returnsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(int): int)`. [invalid-return-statement]"] Line 49: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\acceptsPureCallable`: expected `(pure-callable(...mixed): mixed)`, but found `(closure(int): int)`. [invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Partly enforced (1/3) | phpdoc_advanced_fallback_pure_callable.php:61: InvalidArgument: Argument $value of acceptsPureCallable() expects 'callable', got '1' [MIR0201]
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Unrecognized | phpdoc_advanced_fallback_pure_callable.php:27: Class 'Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable' not found [unknown_class] phpdoc_advanced_fallback_pure_callable.php:31: Return type Closure is incompatible with declared return type Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable [type_mismatch_return] phpdoc_advanced_fallback_pure_callable.php:39: Class 'Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable' not found [unknown_class] phpdoc_advanced_fallback_pure_callable.php:49: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable, got Closure [type_mismatch_argument] phpdoc_advanced_fallback_pure_callable.php:55: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable, got Closure [type_mismatch_argument] phpdoc_advanced_fallback_pure_callable.php:58: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable, got Closure [type_mismatch_argument] phpdoc_advanced_fallback_pure_callable.php:61: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable, got 1 [type_mismatch_argument]
Expectation diffLine 31: Expected valid value to be accepted, got ["Return type Closure is incompatible with declared return type Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\pure-callable [type_mismatch_return]"] Line 49: Expected valid value to be accepted, got ["Argument 1 ($value) expects Conformance\\Tests\\PhpdocAdvancedFallbackPureCallable\\pure-callable, got Closure [type_mismatch_argument]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Partly enforced (1/3) | phpdoc_advanced_fallback_pure_callable.php:61: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable() is expected to be of type callable, int given
|
| qodana | 262.8665.325Qodana 262.8665.325 | Unrecognized | phpdoc_advanced_fallback_pure_callable.php:27: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection] phpdoc_advanced_fallback_pure_callable.php:27: Undefined class 'pure-callable' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_pure_callable.php:31: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection] phpdoc_advanced_fallback_pure_callable.php:39: Undefined class 'pure-callable' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_pure_callable.php:46: Parameter 'returnsPureCallable()' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_pure_callable.php:49: Parameter 'static fn (int $value): int => $value + 1' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_pure_callable.php:55: Parameter '$impureClosure' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_pure_callable.php:58: Parameter 'impureFunction(...)' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_pure_callable.php:61: Parameter '1' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 31: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"] Line 46: Expected valid value to be accepted, got ["Parameter 'returnsPureCallable()' type is not compatible with declaration [PhpParamsInspection]"] Line 49: Expected valid value to be accepted, got ["Parameter 'static fn (int $value): int => $value + 1' type is not compatible with declaration [PhpParamsInspection]"] |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Unrecognized | phpdoc_advanced_fallback_pure_callable.php:27: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable does not exist [undefinedClass] phpdoc_advanced_fallback_pure_callable.php:39: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackPureCallable\pure-callable does not exist [undefinedClass] phpdoc_advanced_fallback_pure_callable.php:55: potentially not safe call in function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable signature of param value [notSafeCall]
|
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Enforced | phpdoc_advanced_fallback_pure_callable.php:55: callable argument to acceptsPureCallable() violates declared @param pure-callable $value — the bound callable's inferred effect envelope is not pure [phpdoc.param-mismatch] phpdoc_advanced_fallback_pure_callable.php:58: callable argument to acceptsPureCallable() violates declared @param pure-callable $value — the bound callable's inferred effect envelope is not pure [phpdoc.param-mismatch] phpdoc_advanced_fallback_pure_callable.php:61: argument 1 to acceptsPureCallable() violates declared @param pure-callable $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_pure_callable.php:55: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): void given. [identifier=argument.type] phpdoc_advanced_fallback_pure_callable.php:58: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, Closure(): int given. [identifier=argument.type] phpdoc_advanced_fallback_pure_callable.php:61: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable(): mixed, 1 given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_fallback_pure_callable.php:55: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but parent type impure-Closure():void provided [ArgumentTypeCoercion] phpdoc_advanced_fallback_pure_callable.php:58: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but parent type impure-Closure():int provided [ArgumentTypeCoercion] phpdoc_advanced_fallback_pure_callable.php:61: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackPureCallable\acceptsPureCallable expects pure-callable, but 1 provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackPureCallable;
/**
* `pure-callable`
*
* A callable with no side effects. Unlike the other callable refinements this
* one cannot be checked from a signature: deciding it means looking inside the
* body for writes, echoes and calls to impure functions. Analyzers that only
* parse the keyword accept any callable here.
*
* References:
* - PHPStan TypeNodeResolver `pure-callable` resolves to CallableType(isPure: yes)
*/
function impureFunction(): int
{
echo 'side effect';
return 1;
}
/**
* @return pure-callable
*/
function returnsPureCallable() // T: pure-callable
{
return static fn (int $value): int => $value + 1; // V
}
function acceptsCallable(callable $value): void
{
}
/**
* @param pure-callable $value
*/
function acceptsPureCallable($value): void // T: pure-callable
{
}
// A `pure-callable` value always satisfies a native `callable` parameter.
acceptsCallable(returnsPureCallable()); // V
// A closure that only computes satisfies the parameter.
acceptsPureCallable(static fn (int $value): int => $value + 1); // V
// A closure that echoes does not.
$impureClosure = static function (): void {
echo 'side effect';
};
acceptsPureCallable($impureClosure); // E?: a closure with side effects is not a pure-callable
// Neither does a named function whose body has side effects.
acceptsPureCallable(impureFunction(...)); // E?: an impure function is not a pure-callable
// A value that is not callable at all fails the base type too.
acceptsPureCallable(1); // E?: 1 is not callable