Phpinspectionsea: False positive: "Return type must be" with null coalesce operator (WI-37013)

Created on 28 Jun 2017  路  4Comments  路  Source: kalessil/phpinspectionsea

PHPStorm version: 2017.2 EAP (172.3198.4)
PHPInspections version: 2.3.8-preview.1

Code:
```php
declare(strict_types = 1);

class Test
{

/**
 * @var int
 */
protected $val;

/**
 * @var ?int
 */
protected $maybeNull = null;


public function testMaybe() : int
{
    return ($this->maybeNull ?? $this->val);
}

}
````

Actual result:
$this->maybeNull is hilighted with the message "Return value must be of type 'int', 'null' returned"

Expected result:
No error hilight - null will never be returned from this function because of the null coalesce operator.

wontfix 3rd party

Most helpful comment

All 4 comments

Thank you for reporting @AllenJB.
I did check and it seems that the message emitted by PhpStorm itself, hence closing the issue.

Ta. I did check, but obviously my eyes deceived me and told me it was under the PHP Inspections EA branch in the inspections list. I've just rechecked and it definitely isn't. My bad.

No problem! I do that too a lot of times. haha

Was this page helpful?
0 / 5 - 0 ratings