noverify icon indicating copy to clipboard operation
noverify copied to clipboard

Type inference in `!instanceof T || <use as T>`

Open quasilyte opened this issue 5 years ago • 1 comments

Code Example

    public function isEmpty($value, $trim = false)
    {
        $value = is_array($value) ? reset($value) : $value;
        return !($value instanceof UploadedFile) || $value->error == UPLOAD_ERR_NO_FILE;
    }

Actual Behavior

NoVerify gives undefined error for error property.

Expected Behavior

Type of $value is inferred as UploadedFile, since conditional expression checks for that.

Note: PhpStorm understands it.

image

quasilyte avatar Nov 01 '19 23:11 quasilyte

Also:

<critical> ERROR   undefined: Call to undefined method {\phpDocumentor\Reflection\Type}->getFqsen() at /home/isharipov/CODE/php/basic/vendor/phpdocumentor/type-resolver/src/TypeResolver.php:398
            && (!$classType instanceof Object_ || $classType->getFqsen() === null)) {                                

quasilyte avatar Nov 02 '19 00:11 quasilyte