-
Notifications
You must be signed in to change notification settings - Fork 547
Fix subtype check for identical late-resolvable conditional types (bug #10942) #4579
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
base: 2.1.x
Are you sure you want to change the base?
Changes from 2 commits
d574aa7
0ba6805
28bd4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug10942; | ||
|
|
||
| class A | ||
| { | ||
|
|
||
| /** | ||
| * @param string|($operator is 'in' ? int : never) $sqlRight | ||
| */ | ||
| protected function _renderConditionBinary(string $operator, string $sqlLeft, $sqlRight): string | ||
| { | ||
| return 'x'; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class B extends A | ||
| { | ||
|
|
||
| #[\Override] | ||
| protected function _renderConditionBinary(string $operator, string $sqlLeft, $sqlRight): string | ||
| { | ||
| return 'y'; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Type; | ||
|
|
||
| use PHPStan\Type\Constant\ConstantStringType; | ||
| use PHPStan\Type\IntegerType; | ||
| use PHPStan\Type\NeverType; | ||
| use PHPStan\Type\UnionType; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class LateResolvableTypeTraitTest extends TestCase | ||
| { | ||
|
|
||
| public function testIsSuperTypeOfForConditional(): void | ||
| { | ||
| $conditional = new ConditionalTypeForParameter( | ||
| '$operator', | ||
| new ConstantStringType('in'), | ||
| new IntegerType(), | ||
| new NeverType(), | ||
| false, | ||
| ); | ||
|
|
||
| $this->assertSame('Yes', $conditional->isSuperTypeOf($conditional)->describe()); | ||
|
|
||
| $unionWithConditional = new UnionType([ | ||
| new StringType(), | ||
| $conditional, | ||
| ]); | ||
|
|
||
| $this->assertSame('Yes', $conditional->isSuperTypeOf($unionWithConditional)->describe()); | ||
|
||
| } | ||
|
|
||
| } | ||
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.
It'd make sense to write some tests that test this method directly. Similar to this:
phpstan-src/tests/PHPStan/Type/UnionTypeTest.php
Lines 174 to 473 in 43e8099
Also, please review and maybe fix the isSuperTypeOf method as well.
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.
Implemented; please take a look
0ba6805