Skip to content

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

Closed
@schodemeiss

Description

@schodemeiss

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