-
-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Labels
Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.Inconsistencies or issues which will cause an issue or problem for users or implementors.
Description
Describe the bug
Type\nonnull() is not narrowed by phpstan
To Reproduce
<?php
require __DIR__.'/../vendor/autoload.php';
use Psl\Type;
/**
* @template T
*
* @param T|null $value
*
* @ara-assert nonnull $value
*
* @psalm-assert T $value
*
* @ara-return nonnull
*
* @return ($value is null ? never : T)
*/
function assertNotNull(mixed $value): mixed
{
}
function a(?int $i): void
{
\PHPStan\dumpType($i);
\PHPStan\dumpType(assertNotNull($i));
}
function b(?int $i): void
{
\PHPStan\dumpType($i);
\PHPStan\dumpType(Type\nonnull()->assert($i));
}Expected behavior
First method shows a way (provided by @ondrejmirtes) that this can work in phpstan.
The second method use Type\nonnull().
The dumped types here should be
int|null followed by int for both dumpTypes. but we get:
27 Dumped type: int|null
28 Dumped type: int
33 Dumped type: int|null
34 Dumped type: mixed
The Psl version of the function "narrows" int|null to mixed, not int
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.Inconsistencies or issues which will cause an issue or problem for users or implementors.