Skip to content

[Bug] Incorrect generic extends of RuleFactoryInterface #595

@KorDum

Description

@KorDum

What are you really trying to do?

There is no correct way to use generic for your marshall-types.

Describe the bug

RuleFactoryInterface is not a generic interface and does not give you the ability to specify your own type:

/**
 * @extends TypeInterface<mixed>
 */
interface RuleFactoryInterface extends TypeInterface {}

Therefore, when using this interface together with an abstract Type (like UuidType) we get this error from phpstan

Class Temporal\Internal\Marshaller\Type\Type specifies template type TMarshalType of interface Temporal\Internal\Marshaller\Type\TypeInterface as int<0, max> but it's already specified as mixed.
🪪 generics.interfaceConflict

Minimal Reproduction

/**
 * @extends Type<non-negative-int>
 */
final class SomeType extends Type implements DetectableTypeInterface, RuleFactoryInterface
{
    #[Override]
    public function parse(mixed $value, mixed $current): Some
    {
        return Some::fromInt($value);
    }

    #[Override]
    public function serialize(mixed $value): int
    {
        return $value->toInt();
    }

    #[Override]
    public static function match(ReflectionNamedType $type): bool
    {
        return !$type->isBuiltin() && $type->getName() === Some::class;
    }

    #[Override]
    public static function makeRule(ReflectionProperty $property): ?MarshallingRule
    {
        $type = $property->getType();

        if (!$type instanceof ReflectionNamedType || !self::match($type)) {
            return null;
        }

        if ($type->allowsNull()) {
            return new MarshallingRule(
                name: $property->getName(),
                type: NullableType::class,
                of: new MarshallingRule(
                    type: self::class,
                    of: $type->getName(),
                ),
            );
        }

        return new MarshallingRule(
            name: $property->getName(),
            type: self::class,
            of: $type->getName(),
        );
    }
}

Environment/Versions

  • Temporal SDK Version: 2.13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions