Skip to content

Fix psalm incompatibility with class-string<object> notation#333

Merged
joelwurtz merged 1 commit intojolicode:mainfrom
blackbirds24:fix/psalm-class-string-error
Mar 17, 2026
Merged

Fix psalm incompatibility with class-string<object> notation#333
joelwurtz merged 1 commit intojolicode:mainfrom
blackbirds24:fix/psalm-class-string-error

Conversation

@blackbirds24
Copy link

Problem

Psalm 6 crashes with an uncaught DocblockParseException when scanning
src/Metadata/Discriminator.php due to the class-string<object> type
in the docblock:

Uncaught Psalm\Exception\DocblockParseException: array<string, class-string<object>> 
is not a valid type (class-string param can only target to named or callable objects)

This crash occurs during autoload scanning, before analysis even starts,
making it impossible to use Psalm on projects that depend on AutoMapper.

Versions affected:

  • AutoMapper: 10.0.3
  • Psalm: 6.15.1

Fix

Replace class-string<object> with class-string in the Discriminator
constructor docblock.

Since every PHP class implicitly extends object, these two types are
strictly equivalent — no type safety is lost.

Copy link
Member

@joelwurtz joelwurtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, since it works on phpstan also

@joelwurtz joelwurtz merged commit a0a2099 into jolicode:main Mar 17, 2026
5 checks passed
@joelwurtz
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants