-
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
(support) "TooManyTemplateParams" for ReflectionAttribute in local, but not in online sandbox #6619
Comments
Please share some code for your errors. Keep in mind that psalm.dev runs on PHP 8.1. changes may have been made on specific classes |
Sorry, I had the wrong link in my initial post. Fixed. |
(to ping the bot) |
I found these snippets: https://psalm.dev/r/5446aafa14<?php
declare(strict_types=1);
namespace N;
/**
* @template T as object
*/
class C {
/**
* @var \ReflectionAttribute<T>
*/
private \ReflectionAttribute $r;
/**
*
* @param \ReflectionAttribute<T> $r
* @param \ReflectionClass<T> $rc
*/
function __construct(\ReflectionAttribute $r, \ReflectionClass $rc) {
$this->r = $r;
}
}
|
Still happening in my local with PHP 8.1. |
Can you add --php-version=8.1 to be sure? I don't reproduce locally when running in PHP 8.0 and --php-version=8.1. I do reproduce when running PHP 8.0 without --php-version=8.1 |
Very interesting. So I see the following problems:
|
Yeah, cache issue are probable when switching things like that. But to get back to the initial point, what is exactly your issue? Do you have a valid piece of code you expect to run on a specific version and where Psalm tells you it's invalid on this version? |
For me it would be desirable to have forward support for attributes. |
Could this be solved by using my own stub? I'm afraid PhpStorm will get confused for duplicate classes. |
Psalm uses the lowest supported php version from your composer.json file to know which version should be used to analyze. You can probably use your own stubs yeah, PHPStorm won't read them if you put them in an extension not recognized as php (for example .phpstub) |
Just for some context: I think the following could be improved in psalm:
For my own project I will see how far I get by adding my own stubs. |
I found these snippets: https://psalm.dev/r/208b9aee01<?php
declare(strict_types=1);
namespace Donquixote\QuickAttributes\RawAttribute;
/**
* @template-covariant T as object
*
* @template-implements RawAttributeInterface<T>
*/
class RawAttribute_NativeReflection implements RawAttributeInterface {
/**
* @var \ReflectionAttribute<T>
*/
private \ReflectionAttribute $attribute;
/**
* Constructor.
*
* @param \ReflectionAttribute $attribute
*/
public function __construct(\ReflectionAttribute $attribute) {
if (PHP_VERSION_ID < 80000) {
throw new \RuntimeException('This class requires PHP 8+.');
}
$this->attribute = $attribute;
}
/**
* @return class-string<T>
*/
public function getName(): string {
return $this->attribute->getName();
}
/**
* {@inheritdoc}
*/
public function getArguments(): array {
return $this->attribute->getArguments();
}
}
https://psalm.dev/r/0e2d6477b7<?php
declare(strict_types=1);
namespace Donquixote\QuickAttributes\RawAttribute;
/**
* @template-covariant T as object
*/
interface RawAttributeInterface {
/**
* @return class-string<T>
*/
public function getName(): string;
/**
* @return array
*
* @throws \ReflectionException
*/
public function getArguments(): array;
}
|
Perhaps another idea could be per-file php version, or even per statement, by looking at "if (PHP_VERSION_ID < ...)" or |
For others who find this thread: <stubs>
<file name="stubs/ReflectionAttribute.phpstub"/>
</stubs> |
Caching could probably be improved yeah but it rarely come up in issues, so not a priority. In theory, we have very few cases where there are difference between the run version and described version. If you have, please share a minimal reproducer. I'm not sure what you mean by forward support exactly. And yeah, flow analysis is pretty complex without adding different php version with different stubs in the mix |
Perhaps my idea is also still quite vague :) This could scale up if an ecosystem like Drupal or symfony starts using userland-parsed attributes, while still supporting PHP 7.4 or lower. Perhaps there are examples other than attributes, but for now this is all I can think of. But it seems for now a lot of this can be solved with custom stubs. So I should see how far I get with this before I open more issues :) |
I'll close this in the meantime. Please open 1 issue per idea/problem. Also keep in mind that your needs as a library maintainer could be the opposite of the need of the majority of users. In most cases, we actually want to prevent users to use a feature that is not yet available in their lowest supported version |
https://psalm.dev/r/5446aafa14
This online sandbox version works just fine
However, in my local env, I get this:
Why might this be? What can I do to debug?
About my local installation:
C.php
, code as in the demo.The text was updated successfully, but these errors were encountered: