Skip to content

property.unusedType error on private properties when @var tag has more than one type and property is assigned indirectly #13624

@RuggMatt

Description

@RuggMatt

Bug report

When defining types using /** @var <type> */ on private properties, I have recently started getting the error message:

Property Example::$exampleProperty (string|null) is never assigned string so it can be removed from the property type.

However, if I switch from using /** var <type> */ comment and just type the property directly, the error goes away.

This error did not exist in version 2.1.28.

I am currently using version 2.1.30.

Code snippet that reproduces the problem

https://phpstan.org/r/2f969a67-0a34-40fb-a7bd-561351b4e432

Expected output

No errors. The error generated is not guaranteed.

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

Great work as always.

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