def matched.visit

bend-lint-rules@0.2.0.0 · language/unneeded_plus.bend:43

import bend-lint-rules@0.2.0.0/language/unneeded_plus.bend as UnneededPlus
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint
import bend-lint-api@0.2.0.0/shared/lists.bend as Lists

43# The binder a variable below `path` uses, if it is taken apart there: it is a match's scrutinee, or the value of a let
44# with a constructor pattern (`Vert{x, y} = v`).
45def matched.visit(+u: Unit, +path: List<&2, Lint.Above>, +node: Lint.Node) -> List<&2, U32>:
46  match path node:
47    case Con{
48      Lint.Above{Lint.Node{Lint.Match{}, n, s, k, f}, at},
49      up
50    } Lint.Node{Lint.Variable{b}, vn, vs, vk, vf}:
51      [b]
52    case Con{
53      Lint.Above{Lint.Node{Lint.Destructure{q}, n, s, +kids, f}, +at},
54      up
55    } Lint.Node{Lint.Variable{b}, vn, vs, vk, vf}:
56      Bool.pick(
57        List<&2, U32>,
58        Bool.not(
59          U32.is_eq((at + 1: U32), U32.from_nat(Lists.length(&2, Lint.Node, kids)))
60        )
61          && is_constructed(kids),
62        [b],
63        []
64      )
65    case _ _:
66      []

Uses (14)

Used by (1)