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
BC issue, help needed #7540
Comments
Hey @zmitic, can you reproduce the issue on https://psalm.dev ? |
Refs #7492 |
@zmitic thanks for the feedback! We're in no particular rush for this one, Psalm 5 hasn't been released (even as alpha) yet, so there is still time to refine features. Glad we have people testing with master for that :) The PR #7492 was made to be a feature ensuring people don't forget annotating their templates. It's supposed to mimick what PHPStan already does for quite some time (even on You find the change too big? Do you have an idea of the number of errors in a typical symfony project? @danog, do you have ideas about what we could do to reduce the impact on end projects? |
@orklah I don't think there's any way to make this rule softer, apart from removing it altogether: this can indeed be considered a BC-breaking feature, and that's why it will be released in 5.0. The raison d'être of this check is precisely to make sure eventual template types aren't forgotten about when extending a class, which is especially useful in the case of iterators. It can also direct Psalm beginners in the right direction by introducing them to template types, directly indicating how they can help in iterators and other places. |
I am into extreme sports; skydiving, paintball, late Friday deploys and using unreleased products 😄
I don't have any errors, and my psalm setup is level 1. For example: when I noticed this change today, it took me < 30 mins to fix my forms, and make PR to remove some useless code in symfony plugin. But I can't talk about other users.
Actually I don't, and I like this decision a lot. But these stubs I made have not been verified by core members; forms can be very dynamic in nature, especially with DataTransformers. So while I don't have a single issue, I am afraid lots of others might. It is not just for form stubs, but other stubbed packages as well. Suggestion for Psalm5; |
I'm happy that you agree with the design decision :D |
You are right, it does make more sense. So different suggestion:
|
You want to check the user_defined property for that? I'm afraid we just saw it was not reliable for now (we'll have to revert/disable your change on ReturnTypeWillChange because of that...) |
I saw, I tried playing around a bit, replacing the $storage->user_defined = true;
if (class_exists($fq_classlike_name)) {
$reflect = new ReflectionClass($fq_classlike_name);
$storage->user_defined = !$reflect->isInternal();
} However I haven't yet managed to reproduce the original issue in the stub tests, will probably give it another go tomorrow. |
Just my 2 cents, migrating to psalm v5 added the |
Yep, this is intended! |
Hi @danog, is this BC also intended for a case where a |
I found these snippets: https://psalm.dev/r/3672bc9542<?php
/**
* @template T of object
*/
class ServiceEntityRepository
{
/**
* @psalm-param class-string<T> $entityClass
*/
public function __construct(string $entityClass)
{
}
}
class FooRepository extends ServiceEntityRepository {
public function __construct() {
parent::__construct(Foo::class);
}
}
class Foo {
}
|
I updated psalm (dev-master) today and suddenly got lots of new errors, all pointing to same problem.
Consider stub file like this one:
Before today, if users did not use template, psalm would not complain and assume
T: mixed
. Which is totally fine, not all forms need correct type due to their dynamic nature.For example:
would work exactly as if I have written:
With latest update, psalm requires this annotation and I can't find the issue that changed this behavior. The result is that all users of symfony/psalm and other stubs will suddenly get lots of errors.
Any suggestions how to mitigate the problem expect for ignoring
MissingTemplateParam
issue?The text was updated successfully, but these errors were encountered: