positive-int / negative-intint parameters would accept every result, so the receivers are
the PHPDoc refinements. 10 + 5 satisfies positive-int; 10 + (-15)
does not. The spellings themselves are phpdoc_advanced_fallback_positive_int
and phpdoc_advanced_fallback_negative_int.
Source: phan/phan#5577 (6.0.8).
References:
- phan#5577| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 | Enforced | native_types_signed_int_inference.php:36: Argument 1 ($value) is (10 + -15) of type int (value: -5) but \Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt() takes positive-int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_signed_int_inference.php:24 [PhanTypeMismatchArgument] native_types_signed_int_inference.php:38: Argument 1 ($value) is (10 + 5) of type int (value: 15) but \Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt() takes negative-int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_signed_int_inference.php:31 [PhanTypeMismatchArgument]
|
| phpstan | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Enforced reported Lv.5+ | native_types_signed_int_inference.php:36: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt expects int<1, max>, -5 given. [reported-from-level=5] native_types_signed_int_inference.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt expects int<min, -1>, 15 given. [reported-from-level=5] With strict-rulesnative_types_signed_int_inference.php:36: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt expects int<1, max>, -5 given. native_types_signed_int_inference.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt expects int<min, -1>, 15 given.
|
| psalm | 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08 next: 7.0.4 |
Enforced | native_types_signed_int_inference.php:36: Argument 1 of Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt expects int<1, max>, but -5 provided [InvalidArgument] native_types_signed_int_inference.php:38: Argument 1 of Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt expects int<min, -1>, but 15 provided [InvalidArgument]
|
| mago | 1.59.0mago 1.59.0 | Enforced | native_types_signed_int_inference.php:36: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt`: expected `positive-int`, but found `int(-5)`. [invalid-argument] native_types_signed_int_inference.php:38: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt`: expected `negative-int`, but found `int(15)`. [invalid-argument]
|
| mir | 0.91.0mir 0.91.0 | Enforced | native_types_signed_int_inference.php:36: InvalidArgument: Argument $value of takesPositiveInt() expects 'positive-int', got '-5' [MIR0201] native_types_signed_int_inference.php:38: InvalidArgument: Argument $value of takesNegativeInt() expects 'negative-int', got '15' [MIR0201]
|
| phpantom | 0.11.1phpantom_lsp 0.11.1 | Enforced | native_types_signed_int_inference.php:36: Argument 1 ($value) expects positive-int, got -5 [type_mismatch_argument] native_types_signed_int_inference.php:38: Argument 1 ($value) expects negative-int, got 15 [type_mismatch_argument]
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Not enforced | No diagnostics reported.
|
| phpy | 1.0.19490phpy 1.0.19490 | Not enforced | No diagnostics reported.
|
| qodana | 262.11879.104PhpStorm 262.11879.104 | Not enforced | No diagnostics reported.
|
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Unrecognized | native_types_signed_int_inference.php:29: Class or interface named \Conformance\Tests\NativeTypesSignedIntInference\negative-int does not exist [undefinedClass]
|
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Not enforced | No diagnostics reported.
|
| phpstan-strict | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Enforced | native_types_signed_int_inference.php:36: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt expects int<1, max>, -5 given. native_types_signed_int_inference.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt expects int<min, -1>, 15 given.
|
| psalm-next | 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f | Enforced | native_types_signed_int_inference.php:36: Argument 1 of Conformance\Tests\NativeTypesSignedIntInference\takesPositiveInt expects int<1, max>, but -5 provided [InvalidArgument] native_types_signed_int_inference.php:38: Argument 1 of Conformance\Tests\NativeTypesSignedIntInference\takesNegativeInt expects int<min, -1>, but 15 provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\NativeTypesSignedIntInference;
/**
* Arithmetic with known signs infers `positive-int` / `negative-int`.
*
* Native `int` parameters would accept every result, so the receivers are
* the PHPDoc refinements. `10 + 5` satisfies `positive-int`; `10 + (-15)`
* does not. The spellings themselves are `phpdoc_advanced_fallback_positive_int`
* and `phpdoc_advanced_fallback_negative_int`.
*
* Source: phan/phan#5577 (6.0.8).
*
* References:
* - https://github.com/phan/phan/pull/5577
*/
/**
* @param positive-int $value
*/
function takesPositiveInt($value): void // T: positive-int
{
}
/**
* @param negative-int $value
*/
function takesNegativeInt($value): void // T: negative-int
{
}
takesPositiveInt(10 + 5); // V
takesPositiveInt(10 + (-15)); // E?: 10 + (-15) is not positive-int
takesNegativeInt((-10) + (-5)); // V
takesNegativeInt(10 + 5); // E?: 10 + 5 is not negative-int