Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] TypeResolver update breaks when non-collection generics are used #49924

Copy link
Copy link
Closed
@schodemeiss

Description

@schodemeiss
Issue body actions

Symfony version(s) affected

6.2.8

Description

Since removing the TypeResolver 1.7 restriction in this commit, I'm getting serialisation errors when classes have docblocks that are not collections.

For example, if I use Psalms "value-of" docblock, the Serializer thinks this is an array of Type, but in reality it's just a string.

How to reproduce

final class StatusClass
{
    final public const STATUS_VALUES = ['accept', 'reject'];

    /**
     * @param value-of<self::STATUS_VALUES> $status
     */
    public function __construct(
        public readonly string $status,
    ) {
    }
}

Attempt to serialise data that looks a little like this and you'll receive an error that $status is an "array".

Possible Solution

  1. Replace in user-land code @param with @psalm-param. Psalm still understands the type, but the serializer doesn't.

  2. Re-add the composer restriction until this issue in TypeResolver is resolved: Generics are always considered as Collection phpDocumentor/TypeResolver#180

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.