Skip to content

Narrowed type lost? #14536

Closed
Closed

Description

@sreichel

Bug report

Please see test code.

Code snippet that reproduces the problem

https://phpstan.org/r/522a319c-1f35-4dd7-b77b-65116c199df2

Expected output

There should be a 2nd error for line 32.

Parameter #1 $to of static method Mapper::map() expects A|array, Closure given.

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

❤️

Activity

  1. changed the title [-]Narrowed type gets lost?[/-] [+]Narrowed type lost?[/+] on Apr 27, 2026
  2. VincentLanglet commented on Apr 27, 2026

    @VincentLanglet
    Contributor

    There is no reason to report an error line 32.
    [$to, 'y'] is an array, even if it's callable.

  3. sreichel commented on Apr 27, 2026

    @sreichel
    Author

    There should be an error for 1st $from parameter?

    $from is closure. L31 should cause two errors.

  4. VincentLanglet commented on Apr 27, 2026

    @VincentLanglet
    Contributor

    You get your error on level 7 https://phpstan.org/r/a84a4840-fbb9-49f3-8779-2ca4db87e3a1

    array|Closure might be accepted by array|A.

    The "maybe" errors are reported on level 7+

  5. sreichel commented on Apr 27, 2026

    @sreichel
    Author

    Thanks.

  6. github-actions commented on May 29, 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.

  7. locked as resolved and limited conversation to collaborators on May 29, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions