Skip to content

Nullability false positive on a complex condition #987

@janedbal

Description

@janedbal

Code snippet that reproduces the problem

class HelloWorld
{
	public function sayHello(?int $a, ?int $b): void
	{
		
		if ($a === null && $b === null) {
			throw new \LogicException();
		}
		
		$this->foo($a !== null ? $a : $b); // error: Parameter #1 $c of method HelloWorld::foo() expects int, int|null given.  
	}
	
	public function foo(int $c){}
}

Expected output

  • calling foo should be ok

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions