-
Couldn't load subscription status.
- Fork 544
Avoid false error on is_subclass_of #4472
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,5 +15,5 @@ class B extends A {} | |
| } | ||
|
|
||
| if (is_subclass_of($b, B::class)) { | ||
| assertType('*NEVER*', $b); | ||
| assertType('Bug6305Types\B', $b);// Could be NEVER | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC - as we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that here it could be never. But correct me if I'm wrong, currently in the type system we cannot make a difference between and no ? Therefor, currently I feel like it's better to
Rather than the opposite. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it implemented in |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,17 +389,29 @@ public function testBug6305(): void | |
| { | ||
| $this->treatPhpDocTypesAsCertain = true; | ||
| $this->analyse([__DIR__ . '/data/bug-6305.php'], [ | ||
| [ | ||
| 'Call to function is_subclass_of() with Bug6305\B and \'Bug6305\\\A\' will always evaluate to true.', | ||
| 11, | ||
| ], | ||
| [ | ||
| 'Call to function is_subclass_of() with Bug6305\B and \'Bug6305\\\B\' will always evaluate to false.', | ||
| 14, | ||
| ], | ||
| // [ | ||
| // 'Call to function is_subclass_of() with Bug6305\B and \'Bug6305\\\A\' will always evaluate to true.', | ||
| // 11, | ||
| // ], | ||
| // [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this is too complicated to be detected since we don't make a difference in ObjectType between the exact class and one of the children. |
||
| // 'Call to function is_subclass_of() with Bug6305\B and \'Bug6305\\\B\' will always evaluate to false.', | ||
| // 14, | ||
| // ], | ||
| ]); | ||
| } | ||
|
|
||
| public function testBug6305b(): void | ||
| { | ||
| $this->treatPhpDocTypesAsCertain = true; | ||
| $this->analyse([__DIR__ . '/data/bug-6305b.php'], []); | ||
| } | ||
|
|
||
| public function testBug13713(): void | ||
| { | ||
| $this->treatPhpDocTypesAsCertain = true; | ||
| $this->analyse([__DIR__ . '/data/bug-13713.php'], []); | ||
| } | ||
|
|
||
| public function testBug6698(): void | ||
| { | ||
| $this->treatPhpDocTypesAsCertain = true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug13713; | ||
|
|
||
| function debug(object $test): void { | ||
| if ($test instanceof \stdClass) { | ||
| echo var_export(\is_subclass_of($test, \stdClass::class, false), true) . \PHP_EOL; | ||
| } | ||
| } | ||
|
|
||
| class test extends \stdClass {} | ||
| debug(new test); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| namespace Bug6305b; | ||
|
|
||
| class A {} | ||
|
|
||
| class B extends A {} | ||
|
|
||
| $b = mt_rand(0, 1) === 0 ? new B() : new A(); | ||
|
|
||
| if (is_subclass_of($b, A::class)) { | ||
| if (is_subclass_of($b, A::class)) { | ||
| echo 'x'; | ||
| } | ||
| } | ||
|
|
||
| if (is_subclass_of($b, B::class)) { | ||
| if (is_subclass_of($b, B::class)) { | ||
| echo 'y'; | ||
| } | ||
| } | ||
|
|
||
| $b = mt_rand(0, 1) === 0 ? A::class : B::class; | ||
|
|
||
| if (is_subclass_of($b, A::class)) { | ||
| if (is_subclass_of($b, A::class)) { | ||
| echo 'x'; | ||
| } | ||
| } | ||
|
|
||
| if (is_subclass_of($b, B::class)) { | ||
| if (is_subclass_of($b, B::class)) { | ||
| echo 'y'; | ||
| } | ||
| } |