Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 6, 2023
1 parent 326528d commit 690619d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,12 @@ public function testDiscussion9053(): void
$this->assertNoErrors($errors);
}

public function testProcessCalledMethodInfiniteLoop(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/process-called-method-infinite-loop.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types = 1);

namespace ProcessCalledMethodInfiniteLoop;

/**
* @template TValue
*/
class Promise{
/** @var TValue|null */
private $value = null;

/** @param \Closure(TValue|null) : void $callback */
public function onResolve(\Closure $callback) : void{
$callback($this->value);
}
}
class HelloWorld
{
/**
* @template TValue
* @param \Generator<int, Promise<TValue|null>, TValue|null, void> $async
*/
public function next(\Generator $async) : void{
$async->next();
if(!$async->valid()) return;
$promise = $async->current();
$promise->onResolve(function($value) use ($async) : void{
$async->send($value);
$this->next($async);
});
}
}

0 comments on commit 690619d

Please sign in to comment.