rsc-binding-count
a name taken to be bound once by counting the patterns that spell it.
- Group
- Code
- Runs
- Optional: run it with
ur lint --rule rsc-binding-count - Level
- warning
- Reads
- Every file
- Fix
- None: a module over syntax is given no SSA values yet
Why
Counting the patterns that bind a name by its spelling counts a name bound in two scopes, or shadowed, as bound twice, and never counts an assignment that writes it again. Whether a variable is written once is what the SSA values say, which only the concurrency rules' modules are given so far.
The fix, as Ur suggests it: ask the SSA values how often the name is written.
For agents
Ask whether a variable is written once from the SSA values, rather than counting the patterns that spell its name.
Example
checks/Once.rscmodule checks::Once
bool bindsOnce(Function f, str n) = size([b | b <- descendants(f), b is Identifier, b == n]) == 1;
$ ur lint --rule rsc-binding-count
warning[rsc-binding-count]: a name taken to be bound once in `f` by counting its patterns
--> ./checks/Once.rsc:3:37 `size([b | b <- descendants(f), b is Identifier, b == n]) == ...`
= hint: ask the SSA values how often the name is written
0 clone classes and 1 `rsc-binding-count` finding in 1 file