← All results

literal-int is a Psalm-only literal-ness marker

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_psalm_literal_int.php

literal-int matches an integer known at analysis time (a literal or a value narrowed to one), not an arbitrary runtime int. Psalm models the distinction; other analyzers do not recognize the keyword and fall back to plain int. References: - Psalm TNonspecificLiteralInt (literal-int)

Analyzer results

AnalyzerVersionResultDiagnostics
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_psalm_literal_int.php:20: Saw possibly unextractable annotation for a fragment of comment '* @param literal-int $value': after literal, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName]
phpdoc_advanced_psalm_literal_int.php:20: Saw a token Phan may have failed to parse after '* @param literal-int $value': after literal, saw '-' [PhanUnextractableAnnotationSuffix]
phpdoc_advanced_psalm_literal_int.php:22: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal [PhanUndeclaredTypeParameter]
phpdoc_advanced_psalm_literal_int.php:29: Argument 1 ($value) is $value of type int but \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt() takes \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_literal_int.php:22 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_psalm_literal_int.php:33: Argument 1 ($value) is 42 of type int (value: 42) but \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt() takes \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_literal_int.php:22 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling not resolved — reported on declaration line(s) 20, 22
  • Enforcement: 1/1 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 33: Expected valid value to be accepted, got ["Argument 1 ($value) is 42 of type int (value: 42) but \\Conformance\\Tests\\PhpdocAdvancedPsalmLiteralInt\\acceptsLiteralInt() takes \\Conformance\\Tests\\PhpdocAdvancedPsalmLiteralInt\\literal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_literal_int.php:22 (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 Unrecognized
phpdoc_advanced_psalm_literal_int.php:22: Function Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt() has parameter $value with no type specified. [identifier=missingType.parameter] [reported-from-level=6]
phpdoc_advanced_psalm_literal_int.php:22: PHPDoc tag @param for parameter $value contains unresolvable type. [identifier=parameter.unresolvableType] [reported-from-level=2]
With strict-rules
phpdoc_advanced_psalm_literal_int.php:22: Function Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt() has parameter $value with no type specified. [identifier=missingType.parameter]
phpdoc_advanced_psalm_literal_int.php:22: PHPDoc tag @param for parameter $value contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 22
  • Enforcement: 0/1 of the expected violations reported — incidental, since the spelling was not resolved
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_advanced_psalm_literal_int.php:29: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt expects literal-int, but parent type int provided [ArgumentTypeCoercion]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
mago 1.46.0mago 1.46.0 Enforced
phpdoc_advanced_psalm_literal_int.php:29: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt`: expected `literal-int`, but possibly received `int`. [possibly-invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
mir 0.70.1mir 0.70.1 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported

Notes: Was measured 'Enforced 1/1' under mir 0.62.0, but that was a parsing artifact, not real enforcement: mir's changelog for 0.63.0 says literal-int/literal-string previously 'fell through to a bogus named-class bound, always failing a genuinely-satisfying literal argument' — it rejected every literal-int argument, valid or not, which is also why a false positive showed up on line 33. 0.63.0 fixed the recognition, and the over-rejection (both the coincidental hit on this probe and the false positive) went away together, leaving the honest state: recognized, not yet enforced.

phpantom 0.9.0phpantom_lsp 0.9.0 Incidental (1/1)
phpdoc_advanced_psalm_literal_int.php:29: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal-int, got int [type_mismatch_argument]
phpdoc_advanced_psalm_literal_int.php:33: Argument 1 ($value) expects Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal-int, got 42 [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 33
Expectation diff
Line 33: Expected valid value to be accepted, got ["Argument 1 ($value) expects Conformance\\Tests\\PhpdocAdvancedPsalmLiteralInt\\literal-int, got 42 [type_mismatch_argument]"]
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
qodana 262.8665.325Qodana 262.8665.325 Unrecognized
phpdoc_advanced_psalm_literal_int.php:20: Undefined class 'literal-int' [PhpUndefinedClassInspection]
phpdoc_advanced_psalm_literal_int.php:29: Parameter '$value' type is not compatible with declaration [PhpParamsInspection]
phpdoc_advanced_psalm_literal_int.php:33: Parameter '42' type is not compatible with declaration [PhpParamsInspection]
  • Recognition: spelling not resolved — reported on declaration line(s) 20
  • Enforcement: 1/1 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 33: Expected valid value to be accepted, got ["Parameter '42' 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 Enforced ⚠ 1 false positive
phpdoc_advanced_psalm_literal_int.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\literal-int does not exist [undefinedClass]
phpdoc_advanced_psalm_literal_int.php:29: potentially not safe call in function Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt signature of param value [notSafeCall]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
  • False positives: line(s) 12
Expectation diff
Line 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedPsalmLiteralInt\\literal-int does not exist [undefinedClass]"]
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Unrecognized
phpdoc_advanced_psalm_literal_int.php:22: Function Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt() has parameter $value with no type specified. [identifier=missingType.parameter]
phpdoc_advanced_psalm_literal_int.php:22: PHPDoc tag @param for parameter $value contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 22
  • Enforcement: 0/1 of the expected violations reported — incidental, since the spelling was not resolved
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_advanced_psalm_literal_int.php:29: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmLiteralInt\acceptsLiteralInt expects literal-int, but parent type int provided [ArgumentTypeCoercion]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedPsalmLiteralInt;

/**
 * `literal-int` is a Psalm-only literal-ness marker.
 *
 * `literal-int` matches an integer known at analysis time (a literal or a value
 * narrowed to one), not an arbitrary runtime `int`. Psalm models the
 * distinction; other analyzers do not recognize the keyword and fall back to
 * plain `int`.
 *
 * References:
 * - Psalm TNonspecificLiteralInt (`literal-int`)
 */

/**
 * @param literal-int $value
 */
function acceptsLiteralInt($value): void // T: literal-int
{
}

function forwardsRuntimeInt(int $value): void
{
    // A general runtime int is not known to be literal.
    acceptsLiteralInt($value); // E?: an arbitrary int is not a literal-int
}

// A literal integer satisfies the parameter.
acceptsLiteralInt(42); // V