-
Notifications
You must be signed in to change notification settings - Fork 667
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
Invert meaning of dupe_key #7475
Conversation
I found these snippets: https://psalm.dev/r/09048f8f8a<?php
interface a {
public function test(): mixed;
}
class b implements a
{
public function test(string $foo) {
return 'foo';
}
}
|
I wonder whether it would be worth it to make the dupe key a mandatory argument for all issues in v5, this seems like a common issue inside psalm... |
8595663
to
56c943d
Compare
This effectively renders the dupe_key useless, maybe it's worth deprecating for v5. |
Do you have a before/after for your snippet? I'm not sure I see what more it will display with your change? |
@orklah It should also mention something about |
Indeed. So it's caused by the fact we emit the same error on the same place. I think an easier answer would be to try to report those errors on the faulty param/return instead of messing with the dupes, no? |
Perhaps, but are there any cases where an error with a different message shouldn't show up? I'm guessing the reason it doesn't use the location of the param/return is because they might not exist. For the return value in this case, where would you put the error? On |
I guess return type could go on method name if needed. Params type on the params and it should be ok. We can see dropping the dupe feature has a dramatical effect on phpunit, I don't think this is the way |
What about this? Seems like that should probably use the same location as a missing return type, whether it's the entire declaration or just the method name. Just so we're on the same page, I think these improvements you're suggesting are a good idea as well, I'm just not so sure this PR is a bad idea either. I think it's at least worth seeing if it improves other cases as well. Unfortunately I don't think our current tests work well for testing this issue, I believe most of them stop as soon as the first issue is added. I think we would need to test it on a real-world project that has a lot of suppressions and see if it turns up valid issues that were clobbered due to the duplicate issue name. Edit: Looks like it might be excessively verbose for |
I found these snippets: https://psalm.dev/r/39e90deadf<?php
class Foo
{
public function foobar(int $a, string $b): void {}
}
class Bar extends Foo
{
public function foobar(int $a) {}
}
|
There even more issues like this, now that I'm actually looking for them during tests, that's why I sent this PR :D |
I think we shouldn't be updating the tests to ignore that, the point of the dupe key is to prevent duplicate issues. The duplicate issue is what should be fixed. Ideally I think we should go through issue by issue and make sure there can't be duplicates, but that's a lot of work. Another option would be to change the dupe key for specific issues like |
That's precisely what I thought, and why I made this PR, instead. Really, I don't understand why the redundant duplicate key was even used in the first place, when the issue message is already perfect for distinguishing and removing duplicate issues. |
I'm guessing it was due to stuff like this
Those two issues have different phrasing, but they're redundant. We should only be showing one of them. I'm guessing for really messy codebases there will end up being a lot of redundant issues that have different phrasing. |
Ah yes, in this case it does make sense, but I'd still like to remove the In practice, almost nothing changes in messy codebases where all errors are either suppressed or baselined, while testing and reproducing issues on psalm.dev becomes much easier (and as a bonus, Psalm won't seem to underperform in comparison to other tools, ie https://psalm.dev/r/66d598df84 vs https://phpstan.org/r/050dffdd-aaab-431a-87cc-9261a166ce9c)! |
I found these snippets: https://psalm.dev/r/66d598df84<?php
class Foo implements Iterator
{
public function current(string $foo) {
return 'foo';
}
public function next($a) {
}
public function key() {}
public function valid(): string
{
return 'foo';
}
public function rewind(): void
{
}
}
|
Changed the semantics of this PR to simply invert the meaning of dupe_key. |
This has become a BC break then, plugins will not expect this change of behaviour. This could be changed in master though. However, if we do that, I'd expect us to be able to remove any dupe key currently in the code (because the goal is practically inverted, so old dupe keys are outdated). Then, there's a work to be done to add dupe keys in order to remove legitimate dupes. For example, those in phpunit right now. |
42e15c9
to
4c54f2b
Compare
4c54f2b
to
9e66c07
Compare
Done, I haven't actually removed all dupe keys as they might still indicate valid duplicates, I've just replaced all |
9e66c07
to
b69e22a
Compare
Rebased, the new psalm issue seems to be caused by an update of the language server, and can be reproduced on master. |
Seems good to me, I have a feeling there may be more duplicates to deal with in the future but at least a duplicate issue is more visible than a missing issue, and they should be simple fixes. |
Thanks! This may end up being reverted if we have bad feedbacks on 5.0 though. The amount of new issues in PHPUnit is kinda worrying |
I was actually considering that earlier, since they were all |
For example in https://psalm.dev/r/09048f8f8a, one issue was hiding the other.