Skip to content

Unwrapping nested generics yields incorrect result #5290

@muglug

Description

@muglug

In the example below this works:

/**
 * @template TInnerPackage of InnerPackage
 * @template TGenericPackage of GenericPackage<TInnerPackage>
 * @param  class-string<TGenericPackage> $class  FQCN to be instantiated
 * @return TInnerPackage
 */
function loadWithDirectUnwrap(string $class) {
    $package = new $class();
    return $package->unwrap();
}

but the indirect unwrapping fails to produce the templated inner class

/**
 * @template TInnerPackage of InnerPackage
 * @template TGenericPackage of GenericPackage<TInnerPackage>
 * @param  class-string<TGenericPackage> $class  FQCN to be instantiated
 * @return TInnerPackage
 */
function loadWithIndirectUnwrap(string $class) {
    $package = new $class();
    return unwrapGeneric($package);
}

https://psalm.dev/r/abe64b4671

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions