|
42 | 42 | use PHPStan\Type\MixedType; |
43 | 43 | use PHPStan\Type\NeverType; |
44 | 44 | use PHPStan\Type\NullType; |
| 45 | +use PHPStan\Type\RecursionGuard; |
45 | 46 | use PHPStan\Type\Traits\ArrayTypeTrait; |
46 | 47 | use PHPStan\Type\Traits\NonObjectTypeTrait; |
47 | 48 | use PHPStan\Type\Traits\UndecidedComparisonTypeTrait; |
@@ -494,21 +495,29 @@ public function equals(Type $type): bool |
494 | 495 |
|
495 | 496 | public function isCallable(): TrinaryLogic |
496 | 497 | { |
497 | | - $hasNonExistentMethod = false; |
498 | | - $typeAndMethods = $this->doFindTypeAndMethodNames($hasNonExistentMethod); |
499 | | - if ($typeAndMethods === []) { |
500 | | - return TrinaryLogic::createNo(); |
501 | | - } |
| 498 | + $result = RecursionGuard::run($this, function (): TrinaryLogic { |
| 499 | + $hasNonExistentMethod = false; |
| 500 | + $typeAndMethods = $this->doFindTypeAndMethodNames($hasNonExistentMethod); |
| 501 | + if ($typeAndMethods === []) { |
| 502 | + return TrinaryLogic::createNo(); |
| 503 | + } |
502 | 504 |
|
503 | | - $results = array_map( |
504 | | - static fn (ConstantArrayTypeAndMethod $typeAndMethod): TrinaryLogic => $typeAndMethod->getCertainty(), |
505 | | - $typeAndMethods, |
506 | | - ); |
| 505 | + $results = array_map( |
| 506 | + static fn (ConstantArrayTypeAndMethod $typeAndMethod): TrinaryLogic => $typeAndMethod->getCertainty(), |
| 507 | + $typeAndMethods, |
| 508 | + ); |
| 509 | + |
| 510 | + $result = TrinaryLogic::createYes()->and(...$results); |
507 | 511 |
|
508 | | - $result = TrinaryLogic::createYes()->and(...$results); |
| 512 | + if ($hasNonExistentMethod) { |
| 513 | + $result = $result->and(TrinaryLogic::createMaybe()); |
| 514 | + } |
509 | 515 |
|
510 | | - if ($hasNonExistentMethod) { |
511 | | - $result = $result->and(TrinaryLogic::createMaybe()); |
| 516 | + return $result; |
| 517 | + }); |
| 518 | + |
| 519 | + if ($result instanceof ErrorType) { |
| 520 | + return TrinaryLogic::createNo(); |
512 | 521 | } |
513 | 522 |
|
514 | 523 | return $result; |
|
0 commit comments