Loosing narrowed type on `Symfony\Contracts\Cache\CacheInterface`

Open
#449 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php, symfony
Domain
tooling

Research direction

Start with the linked reproducer repository and trace the Symfony\Contracts\Cache\CacheInterface call that changes the non-negative-int return type. Compare PHPStan's inferred type before and after the cache call, then verify that the return type remains int<0, max> without introducing new issues.

Written by the indexing model from the issue text.

Description

Bug report

I'm passing a non-negative-int in my method, which is correctly detected by PHPStan. However, it looses it's narrowed type on the way passing through CacheInterface. I'm not sure why.

I created a reproducer repo, as I'm unable to reproduce this issue on Playground.

https://github.com/mvhirsch/phpstan-symfony-cache-reproducer

Code snippet that reproduces the problem

No response

Expected output

No issues. Return type of $this->cache->get() should be int<0, max>, not int.

Did PHPStan help you today? Did it make you happy in any way?

It helps me keeping calm and settled in a hasty project.

Dominant language
PHP
Stars
800
Forks
104
Avg merge
4m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-symfony

All issues in phpstan/phpstan-symfony

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.