~/bend-docscommunity

src/rules/suspicious/eager.bend fails

raw source on the hub · import 0xde9bb08f7de298b03207fb5797ede9a5/src/rules/suspicious/eager.bend as Eager

rule eager: a branch of a Bool.pick calls a recursive def of the same file. Bool.pick is an ordinary def, so both branch arguments are evaluated before the call: the work in a branch runs whatever the condition says, and the condition never saves it. pick catches the self-call and strict the one under Bool.and/or; a call to a neighbour is the same bug and neither sees it (a game's overlap test moved out of a pick branch took a scene from 31 to 55 fps; one gaps(..) in a branch here ran on every file the linter read, 88 s of a 100 s run). Bind the call above the pick (+x = gaps(..)), or take the branch lazily (Lazy.stop, Lazy.or_else from src/lazy/lazy.bend: the last argument is a Unit -> T thunk, applied only on the branch that needs it). Two things keep it off idiomatic code: only a call to a def of this file counts, and only to one that loops (it calls itself, or reaches something that does), since a Base call and a one-line accessor are everywhere and cost nothing; only the branch arguments count, not the type and the condition, which run whatever is written; and what sits after a => is a lambda's body, which the call does not run. The body ends at the next comma of its group, so an argument after it counts again.

7 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../../lazy/lazy.bend as Lazy
import ../calls.bend as Calls