Skip to content

Commit

Permalink
[TypeDeclaration] Handle infinite loop on type recursive itself on Re…
Browse files Browse the repository at this point in the history
…turnTypeFromStrictTypedCallRector (#3487)

* [TypeDeclaration] Handle infinite loop on type recursive itself on ReturnTypeFromStrictTypedCallRector

* eol
  • Loading branch information
samsonasik committed Mar 18, 2023
1 parent e1dd98d commit 4225ebf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\SomeNode;

class SkipTypeRecursiveCallItself
{
public function run(SomeNode $node)
{
return $this->oddLevel($node);
}

protected function oddLevel(SomeNode $node)
{
if ($node->next) {
return $this->evenLevel($node->next);
}
return $node->value;
}

protected function evenLevel(SomeNode $node)
{
if ($node->next) {
return $this->oddLevel($node->next);
}
return $node->value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source;

final class SomeNode
{
public ?SomeNode $next;
public string $value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ private function inferFromReturnedMethodCall(Return_ $return, FunctionLike $orig
return new MixedType();
}

$parentClassMethod = $this->betterNodeFinder->findParentType($return, ClassMethod::class);
if ($parentClassMethod === $originalFunctionLike) {
return new MixedType();
}

return $this->resolveClassMethod($methodReflection, $originalFunctionLike);
}

Expand Down

0 comments on commit 4225ebf

Please sign in to comment.