Skip to content
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

fix error with 0 being considered positive #7487

Merged
merged 1 commit into from Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -1193,7 +1193,7 @@ private static function scrapeIntProperties(

if (!isset($combination->value_types['int'])) {
$combination->value_types['int'] = $all_nonnegative
? new TIntRange(1, null)
? new TIntRange(0, null) // improvement: use min and max literals to bound
: new TNonspecificLiteralInt();
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/IntRangeTest.php
Expand Up @@ -704,6 +704,18 @@ function doAnalysis(): void
'$_arr===' => 'non-empty-array<int<0, max>, int<0, max>>',
],
],
'noErrorPushingBigShapeIntoConstant' => [
'code' => '<?php
class DocComment
{
private const PSALM_ANNOTATIONS = [
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
];
}',
'assertions' => [
],
],
Comment on lines +707 to +718
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test actually fail before the fix? I tried the same thing with the actual values from DocComment but for some reason it passed fine.

Copy link
Collaborator Author

@orklah orklah Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does: https://psalm.dev/r/1529295950.

EDIT: see result from Psalm's bot
EDIT2: also see the failing CI on master. I retrieved the error from there

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I noticed that it started failing after 52 values in there. DocComment must have around 55, so maybe you didn't include them all?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orklah Oh I see what happened, I used --filter for my test, but I forgot paratest doesn't support that, you have to use phpunit directly. I saw the success message and didn't notice it said 0 tests...

];
}

Expand Down