-
Notifications
You must be signed in to change notification settings - Fork 651
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
Added test to detect problems and inconsistencies in CallMap files #6247
Added test to detect problems and inconsistencies in CallMap files #6247
Conversation
- Fixed inconsistencies in callmap delta files (mainly 8.0) - Added several missing changes in the bc_* functions - Added several missing changes in the mb_* functions - Added several missing changes in the xml_parser_* functions - Fixed several issues with sodium_ functions - Removed all but one of the date_* functions. All were marked as having lost the option to return false, despite this only being true for date_format
It's totally optional but something that could be great is to ensure that parameter names are consistent from PHP 8.0 going backward (it's hard to hard code this rule after PHP 8.0 in case of BC breaks). We know that PHP 8.0 is the only version where parameter names matter, and they were not great before so we may as well keep consistency |
You mean that the 7.x deltas are updated to reflect the names as they are in 8.0? I've looked at that. In some cases, I changed the old names to the new ones, but since it doesn't really matter, I didn't waste too much time on it. Most of the names actually reflect the names as they were in the PHP docs at the time (I checked in their Git history), so there is something to say for historical accuracy :-P The problem is that it really only applies to functions that have been changed multiple times during the period 7.1 => 8.0, as otherwise, it's already covered by the Like you said, enforcing for versions from 8.0 onward would be problematic if, in the future, parameter names change,(which we would have to support) |
That's what I meant yeah, but you're right, it's nitpicking at this point |
Like I said, I looked into it, and changing the names wouldn't be too much work if that's something we want. Something completely different: I'm looking at that ci/circleci test that's failing. If I'm not mistaken, that's a false negative. the bcmath functions officially only accept strings as inputs, not numerics: But with PHP's type juggling, and the fact that strict-types is still not in common use, I can understand if we want to allow numerics here as well. But it would be technically wrong. |
I found these snippets: https://psalm.dev/r/81b102f318<?php
declare(strict_types=1);
echo bcdiv(6, '3');
|
About the numeric, yeah, I already made a PR in that repo not so long ago to change the numeric into int|float somewhere else so I think we can cast this one aside. However, I'm more worried about another error in circleci:
|
Yeah, |
I found the cause. Looks like I added the bcadd changes to the 'new' section of the 8.0 delta, but not the 'old' section. So php 7.4 suddenly doesn't have bcadd. |
# Conflicts: # dictionaries/CallMap_80_delta.php
It does, however, raise the point that this is an error the test doesn't yet catch, which it certainly should. I see two options: add a CallMap_00_delta.php file, which contains all the pre-7.1 signatures, as a baseline. Psalm itself will never use it, since InternalCallMapHandler caps delta-parsing at 71 through the The second option would be to integrate that baseline array into the test. I strongly prefer the first option, as the second would require changing the test if one of the old signatures turns out to be incorrect. Opinions? |
I agree that the first option seems better. However, I wouldn't want to afraid new contributors with too much things in here (callmap changes is often an entry point for new contributors). So as long as the filename is clear on what the file does (and maybe some documentation on top too), I'm ok with it |
I think this can also be handled in a more developer-friendly way, at the cost of some duplication. E.g. if we had, in addition to the |
But wouldn't that just compound to the problem? A dev would need to update even more arrays, increasing the chances for errors. And we'd still need a test to check if both arrays are correct, so a baseline list would still be necessary. Or am I misunderstanding you? |
To prevent similar errors, add baseline file with signatures pre-7.1, to help verify delta files are correct. Modify test to use this to detect missing 'old' entries
I've generated a 00_delta file, and modified the test slightly so it will detect errors of the type I made. (adding a modified function to 'new' without adding it to 'old') More tomorrow. |
I would say it's fairly low effort to add one entry for added or removed function and the chance to make mistakes in two places is pretty slim, as long as discrepancies are checked by an automated test (which would be easy to add). Also it's easier to catch issues during code review, and it's easy to cross-check deltas with PHP changelogs this way. It's not bulletproof, but this way seems more manageable to me. |
… several extra error paths
Can you give an example of how you imagine this? Would it essentially be two extra array elements with the contents of I've updated the testdox in the PR description, note the two new lines:
Wouldn't that tell a dev all he needs to know? |
I had something like this in mind: <?php
return [
'added' => [
'ZipArchive::replaceFile',
],
'removed' => [
'image2wbmp',
],
'old' => [
'image2wbmp' => ['bool', 'image' => 'resource', 'filename=' => 'string', 'foreground=' => 'int'],
'imagecolorat' => ['int|false', 'image' => 'resource', 'x' => 'int', 'y' => 'int'],
],
'new' => [
'ZipArchive::replaceFile' => ['bool', 'filepath' => 'string', 'index' => 'string', 'start=' => 'int', 'length=' => 'int', 'flags=' => 'int'],
'imagecolorat' => ['int|false', 'image' => 'GdImage', 'x' => 'int', 'y' => 'int'],
]
]; but now looking at it I think this is still suboptimal. What if we instead had it like this: <?php
return [
'added' => [
'ZipArchive::replaceFile' => ['bool', 'filepath' => 'string', 'index' => 'string', 'start=' => 'int', 'length=' => 'int', 'flags=' => 'int'],
],
'changed' => [
'imagecolorat' => [
'old' => ['int|false', 'image' => 'resource', 'x' => 'int', 'y' => 'int'],
'new' => ['int|false', 'image' => 'GdImage', 'x' => 'int', 'y' => 'int'],
],
],
'removed' => [
'image2wbmp' => ['bool', 'image' => 'resource', 'filename=' => 'string', 'foreground=' => 'int'],
],
]; It would make additions and removals explicit, and changes easier to add and review, as you would have old and new signatures next to each other. It would also prevent the error you had, as 'changed' entries would have a format different to those in 'added'. And all the checks you added that did not require |
I agree that the second option would be a nice improvement. It is very clear (even to new people) what is going on, and leaves very little room for error. I'll have a look at implementing it over the weekend. |
Convert deltafile format to new style proposed by weirdan Modify CallMapTest to use new format Modify InternalCallMapHandler to use new format Move assertions to base testcase
Ok, I've implemented the following changes:
Right now, it passes all tests but one, and that's a just a warning for an unneeded annotation in the PSL code. Since I didn't even change the hash_password() function, I don't think it's a show-stopper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to drop delta_00
, what assurances we'd lose?
I fixed the two docblock issues you mentioned.
Two types of error:
The 00 delta helps detect those errors. The only way to introduce one of these errors, would be to ALSO edit the 00 delta, which would be easier to spot in a PR, as it is clearly marked as generally not needing modification. |
45029fd
to
8c531fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as tests are concerned I think we're good. @bitwise-operators did you use some script to convert deltas to the new format?
Yeah, but nothing special. A couble of array_diff_key and array_intersect_key calls and some code to write it back to the file. |
Thanks! |
I came across several functions where the 8.0 changes had been added to the Delta file, but not the main CallMap.
Since it was a significant number, I wrote a simple test to detect those conflicts, as well as several other possible errors with the CallMap files.
Of course, after writing the test, I fixed the errors it found, and in doing so, found several other things that were missing or faulty, mostly in the 8.0 changes:
Testdox for the new test: