Skip to content

False type_mismatch_argument for int<0..max> passed to non-negative-int #170

@alexchexes

Description

@alexchexes

PHPantom version

phpantom_lsp 0.8.0-dirty

Installation method

Pre-built binary from GitHub Releases

Operating system

Windows x86_64

Editor

VS Code

Bug description

PHPantom reports a type mismatch when int<0..max> is passed to a parameter typed as non-negative-int.

Expected: no diagnostic. int<0..max> is compatible with non-negative-int.

Actual: PHPantom reports Argument 1 ($count) expects non-negative-int, got int<0..max>.

Steps to reproduce

  1. Use any supported PHP version.
  2. Create a PHP file with:
<?php

/**
 * @param non-negative-int $count
 */
function addCount(int $count): void
{
}

function test(array $items): void
{
    addCount(count($items));
}
  1. Run diagnostics.

PHPantom reports:

12  Argument 1 ($count) expects non-negative-int, got int<0..max>
    type_mismatch_argument

Error output or panic trace


.phpantom.toml

Additional context

This came from a PHPUnit-style call where count($actual) is passed to a method expecting non-negative-int.

Binary source

Originally observed in the VS Code extension v0.5.0. Reproduced with the extension-cached GitHub Releases binary

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions