Skip to content

Commit

Permalink
Fix missing method Generator::throw()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 29, 2020
1 parent af9f4e2 commit 153c874
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function __construct(

public function hasClass(string $className): bool
{
if (strtolower($className) === 'generator') {
return true;
}

if ($this->isClassBlacklisted($className)) {
return false;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1470,4 +1470,20 @@ public function testBug3481(): void
]);
}

public function testBug3683(): void
{
if (self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires hybrid reflection.');
}
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-3683.php'], [
[
'Parameter #1 $exception of method Generator<mixed,mixed,mixed,mixed>::throw() expects Throwable, int given.',
7,
],
]);
}

}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3683.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bug3683;

function (\Generator $g): void {
$g->throw(new \Exception());
$g->throw(1);
};

0 comments on commit 153c874

Please sign in to comment.