azjezz / psl

📚 PHP Standard Library - a modern, consistent, centralized, well-typed, non-blocking set of APIs for PHP programmers
MIT License
1.21k stars 71 forks source link

Is nonnull helpful in any way? #473

Closed zerkms closed 5 months ago

zerkms commented 5 months ago

Describe the bug A clear and concise description of what the bug is.

        /** @var null|int $v */
        $v = 5;

        /** @psalm-trace $v */;

        $v2 = Type\nonnull()->assert($v);

        /** @psalm-trace $v2 */;
ERROR: Trace - f.php:50:31 - $v: int|null (see https://psalm.dev/224)
        /** @psalm-trace $v */;

ERROR: MixedAssignment - f.php:52:9 - Unable to determine the type that $v2 is being assigned to (see https://psalm.dev/032)
        $v2 = Type\nonnull()->assert($v);

ERROR: Trace - f.php:54:32 - $v2: mixed (see https://psalm.dev/224)
        /** @psalm-trace $v2 */;

So, what's the point to have it at all?

To Reproduce Code to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

veewee commented 5 months ago

@zerkms This is recently fixed through https://github.com/azjezz/psl/pull/465 We are working on the release of v3 which will contain this improvement.

I'dd say it's rather a limitation of psalm than this package though ;)