diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index c9e89e5841..cc2030bb4e 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1248,10 +1248,13 @@ public function getEnumCases(): array public function isCallable(): TrinaryLogic { - $parametersAcceptors = $this->findCallableParametersAcceptors(); + $parametersAcceptors = RecursionGuard::run($this, fn () => $this->findCallableParametersAcceptors()); if ($parametersAcceptors === null) { return TrinaryLogic::createNo(); } + if ($parametersAcceptors instanceof ErrorType) { + return TrinaryLogic::createNo(); + } if ( count($parametersAcceptors) === 1 diff --git a/src/Type/RecursionGuard.php b/src/Type/RecursionGuard.php index 2149fb1015..8fd995882c 100644 --- a/src/Type/RecursionGuard.php +++ b/src/Type/RecursionGuard.php @@ -9,10 +9,11 @@ class RecursionGuard private static array $context = []; /** - * @param callable(): Type $callback - * + * @template T + * @param callable(): T $callback + * @return T|ErrorType */ - public static function run(Type $type, callable $callback): Type + public static function run(Type $type, callable $callback) { $key = $type->describe(VerbosityLevel::value()); if (isset(self::$context[$key])) {