language/reused_binder.bend checks
raw source on the hub · import bend-lint-rules@0.3.2.0/language/reused_binder.bend as Reused_binder
language/reused_binder: a binder written without + that live code uses twice on one path, so the
check fails ("consumed more than once").
Heuristics: it checks only the binders whose quantity the syntax gives for sure: a parameter or a
let's name written without +, which can be used once on each path. It leaves out a pattern's
field, whose quantity also comes from its scrutinee's type, and a law's bare parameter. Two uses are
on one path unless they are in different cases of one match. Both values of a call count, so
Bool.pick(T, c, x, x) uses x twice. Uses in types are dead and do not count. A binder that a
match takes apart is skipped: in a case, it stands for the matched constructor. Bend's checker
stops at its first error; this rule reports every such binder at once.
4 imports
import Base import bend-lint-api@0.3.2.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.2.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.2.0/shared.bend as Shared
Types
type Once source · line 19 · raw
Data
A binder that can be used once: its number, and its name.
Once@binder:U32 -> @name:String -> Once
type Seen source · line 24 · raw
Data
The live uses of one binder among some nodes: the first, and the first that an earlier one on its path precedes, if any. Two uses are on one path unless a match parts them: its cases, and its scrutinees, are each a path of their own.
Seen@first:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @second:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> Seen
Definitions
def message source · line 29 · raw
@+name:String -> String
Functions =========
def Once.of source · line 39 · raw
@+bare:Bool -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, Once>
The binders a definition declares that can be used once, as their syntax says for sure: a parameter written without
+ (unless one is bare: its quantity is its law's), and a let's name written without +. A pattern's field is left
out: its quantity also comes from its scrutinee's type (a field of a List<&2, A> is reusable), which the rule cannot
see.
def scrutinee source · line 53 · raw
@+u:Unit -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, U32>
The binders a match takes apart: the variables right under it, its scrutinees. In a case, they stand for the matched constructor.
def is_live_inside source · line 65 · raw
@+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @live:Bool -> Bool
Whether the nodes under node, which is live if live, are: a body is; a type is not (an equality, a function or
pair type, a type's arguments). An annotation's type is not either: see scan.
def is_match source · line 80 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Bool
def is_annotation source · line 87 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Bool
def Seen.of source · line 95 · raw
@+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @b:U32 -> @live:Bool -> @under:Seen -> Seen
What a node's uses of b are: its own, if it is a live use, else under's, those under it.
def Seen.then source · line 103 · raw
@apart:Bool -> @seen:Seen -> @next:Seen -> Seen
The uses of seen, then those of next, the nodes after them: on one path, or, if apart, on paths of their own.
def scan source · line 115 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+b:U32 -> @+live:Bool -> @+apart:Bool -> @+typed:Bool -> @+at:U32 -> @seen:Seen -> Seen
The live uses of b among nodes, the nodes under one, after seen: live says whether they are live, apart
whether each is a path of its own (a match's), and typed whether only the first is live (an annotation's: the
second is a type); at counts the nodes.
def finding source · line 157 · raw
@second:Seen -> @name:String -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def judged source · line 163 · raw
@matched:Bool -> @owner:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @b:U32 -> @name:String -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The finding about a binder of owner used twice on one path, unless a match takes it apart (matched).
def judge source · line 172 · raw
@+owner:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @onces:List<&2, Once> -> @+matched:List<&2, U32> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The finding about each of onces, binders of owner, used twice on one path, onto out; a binder a match takes
apart (matched) is skipped.
def defs source · line 194 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def run source · line 218 · raw
@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)
def rule source · line 221 · raw
0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule