Repository navigation
Require ternary arm remainders to be disjoint from the other arm in both isSuperTypeOf() directions before recording conditional expressions
#7094
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
Open
phpstan-bot
wants to merge
2
commits into
phpstan:2.3.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-c5s4k58
base: 2.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Analyser; | ||
|
|
||
| use PHPStan\Testing\TypeInferenceTestCase; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
|
|
||
| /** | ||
| * Runs without bleeding edge, so that constant arrays are not sealed. | ||
| */ | ||
| class Bug15760Test extends TypeInferenceTestCase | ||
| { | ||
|
|
||
| public static function dataFileAsserts(): iterable | ||
| { | ||
| yield from self::gatherAssertTypes(__DIR__ . '/data/bug-15760.php'); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed ...$args | ||
| */ | ||
| #[DataProvider('dataFileAsserts')] | ||
| public function testFileAsserts( | ||
| string $assertType, | ||
| string $file, | ||
| ...$args, | ||
| ): void | ||
| { | ||
| $this->assertFileAsserts($assertType, $file, ...$args); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug15760; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| function f(string $unit, bool $blur): string | ||
| { | ||
| $units = $blur ? ['px', 'rem'] : ['px', 'rem', '%']; | ||
|
|
||
| if (!in_array($unit, $units, true)) { | ||
| return 'none'; | ||
| } | ||
|
|
||
| assertType('bool', $blur); | ||
|
|
||
| return $blur ? 'blur' : 'distance'; | ||
| } | ||
|
|
||
| function reversedArms(string $unit, bool $blur): void | ||
| { | ||
| $units = $blur ? ['px', 'rem', '%'] : ['px', 'rem']; | ||
| if (!in_array($unit, $units, true)) { | ||
| return; | ||
| } | ||
| assertType('bool', $blur); | ||
| } | ||
|
|
||
| function stringKeys(string $unit, bool $blur): void | ||
| { | ||
| $units = $blur ? ['a' => 'px'] : ['a' => 'px', 'b' => 'rem']; | ||
| if (!in_array($unit, $units, true)) { | ||
| return; | ||
| } | ||
| assertType('bool', $blur); | ||
| } | ||
|
|
||
| function ifElse(string $unit, bool $blur): void | ||
| { | ||
| if ($blur) { | ||
| $units = ['px', 'rem']; | ||
| } else { | ||
| $units = ['px', 'rem', '%']; | ||
| } | ||
| if (!in_array($unit, $units, true)) { | ||
| return; | ||
| } | ||
| assertType('bool', $blur); | ||
| } | ||
|
|
||
| function matchArms(string $unit, int $i): void | ||
| { | ||
| $units = match ($i) { | ||
| 1 => ['px', 'rem'], | ||
| default => ['px', 'rem', '%'], | ||
| }; | ||
| if (!in_array($unit, $units, true)) { | ||
| return; | ||
| } | ||
| assertType('int', $i); | ||
| } | ||
|
|
||
| function disjointArmsStillNarrow(bool $blur): void | ||
| { | ||
| $units = $blur ? ['px', 'rem'] : ['em']; | ||
| if ($units === ['em']) { | ||
| assertType('false', $blur); | ||
| } else { | ||
| assertType('true', $blur); | ||
| } | ||
| } | ||
|
|
||
| function remainderMaybeSupertypeOfOtherArm(bool $blur, string $s): void | ||
| { | ||
| $units = $blur ? ['px', 'rem'] : ['px', $s, '%']; | ||
| if ($units === ['px', 'rem', '%']) { | ||
| assertType('bool', $blur); | ||
| } | ||
| } | ||
|
|
||
| function remainderMaybeSupertypeOfOtherArmReversed(bool $blur, string $s): void | ||
| { | ||
| $units = $blur ? ['px', $s, '%'] : ['px', 'rem']; | ||
| if ($units === ['px', 'rem', '%']) { | ||
| assertType('bool', $blur); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
in https://github.com/phpstan/phpstan-src/pull/7095/files#diff-5330012288c961f747397e9ce43ad8efc3b0cd3461a646a6f38178c5431dba9fR11 we added a similar test.
can we consolidate all tests which extend
extends TypeInferenceTestCaseand do not have any specific use-case but just don't enable bleeding edge?something like
NoBleedingEdgeTypeInferenceTestCaseThere 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.
I've consolidated the test classes into one, committed it as
0bf009d38(not pushed), andmake phpstanandmake testsboth pass.What changed
Bug10980Test,Bug15736TestandBug15760Testwere identical single-file tests that only existed to run without bleeding edge. I deleted all three.tests/PHPStan/Analyser/data/no-bleeding-edge/.tests/PHPStan/Analyser/NoBleedingEdgeTypeInferenceTest.phpruns every file in that directory, without bleeding edge. Adding a new case is now just dropping a file there; no new test class is needed. Because the directory sits underdata/, it's already excluded from lint, phpcs and phpstan, so no config changes were needed.ScopePhpVersionTestandTypeInferenceTestCaseTestas they are. They also extendTypeInferenceTestCasewithout bleeding edge, but they test specific things rather than just running a data file.Checks
AssignHandler.phpfix temporarily reverted, 3 of them fail (the bug-15760 cases), so the test still catches the bug after the move.make tests: 23866 tests pass, 116 skipped.The PR #7095 test the reviewer linked isn't on this branch (I couldn't fetch that PR here), so it can move into the new directory once one of the two PRs is merged.
I didn't do anything about staabm's earlier question on whether the escaped mutations can be killed. I couldn't open the CI mutation report from here, and this review was only about consolidating the tests, so that question is still open.