-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwrapping nested generics yields incorrect result #5290
Labels
Comments
I found these snippets: https://psalm.dev/r/abe64b4671<?php
interface BasePackage {}
interface InnerPackage extends BasePackage {}
/**
* @template TInnerPackage of InnerPackage
*/
interface GenericPackage extends BasePackage {
/** @return TInnerPackage */
public function unwrap() : InnerPackage;
}
interface SomeInnerPackage extends InnerPackage {}
/**
* @extends GenericPackage<SomeInnerPackage>
*/
interface SomePackage extends GenericPackage {}
/**
* @template TInnerPackage of InnerPackage
* @template TGenericPackage of GenericPackage<TInnerPackage>
* @param TGenericPackage $package
* @return TInnerPackage
*/
function unwrapGeneric(GenericPackage $package) {
return $package->unwrap();
}
/**
* @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();
}
/**
* @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);
}
$result = loadWithDirectUnwrap(SomePackage::class);
/** @psalm-trace $result */
// expected: SomePackage|SomeInnerPackage
|
muglug
added a commit
that referenced
this issue
Feb 27, 2021
This was referenced Mar 15, 2021
Closed
This was referenced Mar 17, 2021
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the example below this works:
but the indirect unwrapping fails to produce the templated inner class
https://psalm.dev/r/abe64b4671
The text was updated successfully, but these errors were encountered: