-
Notifications
You must be signed in to change notification settings - Fork 680
The issue message for the $<tmp coalesce var>101 is not understandable #9807
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
Comments
I found these snippets: https://psalm.dev/r/ec8201d718<?php
function test_function(?int $number):array {
return $number ? [$number] : [];
}
var_dump(test_function(null) ?? []);
|
It comes from here: psalm/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php Line 46 in 1c19260
When processing a coalesce operator, Psalm will create a fake expression that looks like this: the I agree the current syntax is confusing, feel free to make a PR and propose something better (keep in mind that it should be a unique name and must not be something that could already be a variable in the scope) |
@orklah I've noticed an issue related to Psalm errors and code readability in our project. I'm planning to work on this by introducing a more descriptive variable name in a coalesce operation. Would appreciate any thoughts or collaboration on this. Thanks! |
CoalesceAnalyzer is in need of a lot of love! We have multiple bugs related to the logic in here and the fact that we transform the coalesce into a fake ternary is causing some of those. But if you want to focus on the readability issue, my previous message summarized what is needed, a unique string that can't conflict with any variable in the scope nor any other similar ternary (for example, imagine your have We could maybe go with |
Got it, will fix this issue and raise a PR for the same, At the same time feel you to share more issues that are related to this. Will try and help on them too! |
This change makes the error messages more understandable. Instead of: Type array<array-key, mixed> for $<tmp coalesce var>101 is never null You'll now see something like: Type array<array-key, mixed> for $coalesce_temp_line7_pos101 is never null
https://psalm.dev/r/ec8201d718
The description of the issues is not understandable. The term
$<tmp coalesce var>101
doesn't explain what's wrong exactly. The phrase$<tmp coalesce var>101
should be probably annotated differently.The text was updated successfully, but these errors were encountered: