Skip to content

False positive: Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true #191

Description

@melkamar

The following code causes a false PHPStan error. The Assert::allInArray($enabledNames, $supportedNames); assertion certainly isn't always true.

use Webmozart\Assert\Assert;

class C
{
    /**
     * @param array<string> $supportedNames
     * @param array<string> $enabledNames
     */
    public function __construct(
        array $supportedNames,
        array $enabledNames,
    )
    {
        Assert::allInArray($enabledNames, $supportedNames);
    }
}
$ vendor/bin/phpstan analyse -c phpstan.neon test.php
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ --------------------------------------------------------------------------------------------------------------------------------
  Line   test.php
 ------ --------------------------------------------------------------------------------------------------------------------------------
  17     Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true.
         🪪  staticMethod.alreadyNarrowedType
 ------ --------------------------------------------------------------------------------------------------------------------------------



 [ERROR] Found 1 error


===============


$ vendor/bin/phpstan diagnose
Note: Using configuration file /Users/melka/work/rh/phpstan.neon.
PHP runtime version: 8.3.22
PHP version for analysis: 8.3.22 (from runtime)

PHPStan version: 2.1.29
PHPStan running from:
/Users/melka/work/rh/vendor/phpstan/phpstan

Extension installer: Not installed

Included configs from Composer packages:
phpstan/phpstan-webmozart-assert (extension.neon): 2.0.0

Discovered Composer project root:
/Users/melka/work/rh


===============


$ cat phpstan.neon
includes:
    - vendor/phpstan/phpstan-webmozart-assert/extension.neon
parameters:
    level: 4  # lowest level where this starts happening

Also discussed in #142 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions