def is_tail

bend-lint-rules@0.2.0.0 · performance/deep_call_in_fork.bend:32

import bend-lint-rules@0.2.0.0/performance/deep_call_in_fork.bend as DeepCallInFork
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint

32# Whether the node below `path` is in a tail position, if it ends the node above it (`ends`): the body of a definition
33# or a case, or the rest of a block after its lets, through annotations.
34def is_tail(path: List<&2, Lint.Above>, ends: Bool) -> Bool:
35  match path ends:
36    case _ False{}:
37      False{}
38    case Con{Lint.Above{Lint.Node{Lint.Body{}, n, s, k, f}, at}, rest} True{}:
39      True{}
40    case Con{Lint.Above{Lint.Node{Lint.Case{}, n, s, k, f}, at}, rest} True{}:
41      is_tail(rest, True{})
42    case Con{Lint.Above{Lint.Node{Lint.Match{}, n, s, k, f}, at}, rest} True{}:
43      is_tail(rest, True{})
44    case Con{Lint.Above{Lint.Node{Lint.Annotation{}, n, s, k, f}, at}, rest} True{}:
45      is_tail(rest, True{})
46    case Con{Lint.Above{Lint.Node{Lint.Destructure{q}, n, s, kids, f}, at}, rest} True{}:
47      is_tail(rest, is_last(kids, at))
48    case Con{Lint.Above{Lint.Node{Lint.Let{}, n, s, kids, f}, at}, rest} True{}:
49      is_tail(rest, is_last(kids, at))
50    case _ _:
51      False{}

Uses (6)

Used by (1)