Skip to content

False type_mismatch_argument after assignment in previous if branch #167

@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 in an elseif condition after the previous if branch assigns a different type to the same variable.

Expected: no diagnostic. The elseif condition only runs when the first branch did not run, so the assignment inside the first branch should not affect the argument type in the elseif condition.

Actual: PHPantom reports Argument 1 ($string) expects string, got bool.

Steps to reproduce

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

function normalizeBooleanString(string $value): bool
{
    if (mb_strtolower($value) === 't') {
        $value = true;
    } elseif (mb_strtolower($value) === 'f') {
        $value = false;
    }

    return (bool) $value;
}
  1. Run diagnostics.

PHPantom reports:

7  Argument 1 ($string) expects string, got bool
   type_mismatch_argument

Error output or panic trace


.phpantom.toml

Additional context

This looks like path-insensitive propagation from the first if branch into the elseif condition. The assignment $value = true can affect code after the whole if / elseif, but it cannot affect the condition of the elseif branch itself.

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