-
Notifications
You must be signed in to change notification settings - Fork 665
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
class-string-map is not working as documented #10095
Comments
Hey @stof, can you reproduce the issue on https://psalm.dev ? |
see https://psalm.dev/r/6f7e81fe99 for a reproducer, which is literally a copy-paste of the example in the documentation of |
I found these snippets: https://psalm.dev/r/6f7e81fe99<?php
/**
* @psalm-consistent-constructor
*/
class Foo {}
/**
* @psalm-consistent-constructor
*/
class Bar extends Foo {}
class A {
/** @var class-string-map<T of Foo, T> */
private static array $map = [];
/**
* @template U of Foo
* @param class-string<U> $class
* @return U
*/
public static function get(string $class) : Foo {
if (isset(self::$map[$class])) {
return self::$map[$class];
}
self::$map[$class] = new $class();
return self::$map[$class];
}
}
$foo = A::get(Foo::class);
$bar = A::get(Bar::class);
/** @psalm-trace $foo */; // Foo
/** @psalm-trace $bar */; // Bar
|
Fixed in #10326 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The documentation shows
class-string-map<T of Foo, SomethingBasedOn<T>>
while the working syntax isclass-string-map<T as Foo, SomethingBasedOn<T>>
. It looks likeof
does not work there, onlyas
(unlike in@template
).The text was updated successfully, but these errors were encountered: