Skip to content

Problem with nested generic types #14002

Closed
phpstan/phpstan-src
#6754

Description

@wiseguy1394

Bug report

I have some errors with nested types.
PhpStan seems to accept wrong types but does not accept correct type.
#13994

Code snippet that reproduces the problem

https://phpstan.org/r/f853cba7-6ea6-4b83-a58c-4d6884ea721c
https://phpstan.org/r/e933925c-b8ef-4a12-bc62-4c5db8b7890e

Expected output

Expected output -> no errors!

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

No response

Activity

  1. deleted a comment from mergeable on Feb 10, 2026
  2. added this to the Generics milestone on Feb 10, 2026
  3. ondrejmirtes commented on Feb 10, 2026

    @ondrejmirtes
    Member

    /cc @jiripudil Is this code sound even with invariant @template?

  4. jiripudil commented on Feb 10, 2026

    @jiripudil
    Contributor

    Hi, yep, the code looks absolutely fine.

    It's just a hunch, but my first thought went to #9074 (reply in thread) (MixedType vs StrictMixedType in an ancestor) – was that ever remediated?

  5. ondrejmirtes commented on Feb 10, 2026

    @ondrejmirtes
    Member

    It wasn't yet. But it's probably the cause here because no error is reported on level 8?

  6. jiripudil commented on Feb 10, 2026

    @jiripudil
    Contributor

    Looks like it then. The problem goes away when you replace mixed with a specific type in the first reproduction.

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