Skip to content

Commit 44c4030

Browse files
committed
Prevent infinite recursion in TypeUtils.resolveTypeForPipeCompletion by not looping over type variables
1 parent cc9987e commit 44c4030

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

analysis/src/TypeUtils.ml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ let rec digToRelevantTemplateNameType ~env ~package ?(suffix = "")
526526
| _ -> (t, suffix, env))
527527
| _ -> (t, suffix, env)
528528

529-
let rec resolveTypeForPipeCompletion ~env ~package ~lhsLoc ~full ?(depth = 0)
529+
let rec resolveTypeForPipeCompletion ~env ~package ~lhsLoc ~full
530530
(t : Types.type_expr) =
531531
(* If the type we're completing on is a type parameter, we won't be able to
532532
do completion unless we know what that type parameter is compiled as.
@@ -539,16 +539,9 @@ let rec resolveTypeForPipeCompletion ~env ~package ~lhsLoc ~full ?(depth = 0)
539539
| _ -> None
540540
in
541541
match typFromLoc with
542+
| Some ({desc = Tvar _} as t) -> (env, t)
542543
| Some typFromLoc ->
543-
(* Prevent infinite loops when `typFromLoc` is a type variable by bailing out after
544-
10 iterations.
545-
TODO: fix the root of the issue (probably in `findReturnTypeOfFunctionAtLoc`)
546-
instead of enforcing a maximum number of iterations. *)
547-
if depth > 10 then (env, typFromLoc)
548-
else
549-
typFromLoc
550-
|> resolveTypeForPipeCompletion ~lhsLoc ~env ~package ~full
551-
~depth:(depth + 1)
544+
typFromLoc |> resolveTypeForPipeCompletion ~lhsLoc ~env ~package ~full
552545
| None ->
553546
let rec digToRelevantType ~env ~package (t : Types.type_expr) =
554547
match t.desc with

0 commit comments

Comments
 (0)