Skip to content

Issue with MathUtilityTypeSpecifyingExtension #181

@alexanderschnitzler

Description

@alexanderschnitzler

Hi folks,

I get the following issue with MathUtilityTypeSpecifyingExtension.

function foo(string $value) 
{

    // At this point phpstan properly assumes that $value is string

    if (MathUtility::canBeInterpretedAsInteger($value)) {
            return (int)$value;
    }

    // At this point phpstan falsely assumes that $value is numeric-string and throws errors in the following match statement.

    return match ($value) {
        '' => null,
        'true' => true,
        'false' => false,
        default => $value,
    };
}

It seems like whenever MathUtility::canBeInterpretedAsInteger() is called on a variable, it's type is changed to numeric-string no matter the outcome.

 ------ ------------------------------------------------------------------------------ 
  55     Dumped type: string                                                           
  61     Dumped type: numeric-string                                                   
  64     Match arm comparison between numeric-string and '' is always false.           
  65     Match arm comparison between numeric-string and 'true' is always false.       
  66     Match arm comparison between numeric-string and 'false' is always false.      
 ------ ------------------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions