Skip to content

Increment/decement should reset int range #2954

@b1rdex

Description

@b1rdex

https://phpstan.org/r/62477238-a0bd-4fca-95fb-e4d9b1f36422

<?php declare(strict_types = 1);

class HelloWorld
{
	public function sayHello(): void
	{
		$a = mt_rand();
		
		if ($a === 0) {return;}
		
		// this shoud reset $a range
		$a--;
		
        // bug: Strict comparison using === between int<1, max>|int<min, -1> and 0 will always evaluate to false.
		if ($a === 0) {return;}
	}
}

PHPStan should reset int range after $a-- call. Same for $a++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions