Skip to content

Covariant false-positive with lower case string union #11835

Closed
phpstan/phpstan-src
#6332

Description

@calebdw

Bug report

Hello!

We started getting errors with the linked code after updating from 1.12.5 => 1.12.6. It seems like some of the recent work on lowercase-string might be the issue? Using string as opposed to non-falsy-string results in a bit more description with a lower-case string union:

https://phpstan.org/r/ed43598d-6192-4c50-8417-51225123b0e3

Thanks!

Code snippet that reproduces the problem

https://phpstan.org/r/8ae98159-3199-4b9a-8b74-aed8354f8533

Expected output

There should not be any errors

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

Always!

Activity

  1. ondrejmirtes commented on Oct 12, 2024

    @ondrejmirtes
    Member

    /cc @VincentLanglet I'm not asking you to fix this problem, that's not easy, but VerbosityLevel should set the correct level so that this error message also includes lowercase-string: https://phpstan.org/r/8ae98159-3199-4b9a-8b74-aed8354f8533

    As a workaround for this issue unfortunately you need to repeat the type in @var: https://phpstan.org/r/a9e347e3-a37c-4b36-87d0-13d299ff88b0

  2. added this to the Generics milestone on Oct 12, 2024
  3. VincentLanglet commented on Oct 12, 2024

    @VincentLanglet
    Contributor

    Can also be solved this way https://phpstan.org/r/a938a60a-1326-4261-887d-4e02e77daac6

    I'll see what can I do for the Verbosity.

  4. phpstan-bot commented on Oct 13, 2024

    @phpstan-bot
    Contributor

    @calebdw @ondrejmirtes After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -37: Method ProjectionCumulativeHeadersResolver::resolve() should return Collection<int, non-falsy-string> but returns Collection<int, non-falsy-string>.
    +37: Method ProjectionCumulativeHeadersResolver::resolve() should return Collection<int, non-falsy-string> but returns Collection<int, lowercase-string&non-falsy-string>.
    Full report
    Line Error
    37 Method ProjectionCumulativeHeadersResolver::resolve() should return Collection<int, non-falsy-string> but returns Collection<int, lowercase-string&non-falsy-string>.
  5. github-actions commented on Oct 9, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  6. locked as resolved and limited conversation to collaborators on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions