~/bend-docscommunity

src/rules/suspicious/table.bend fails

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

rule table: List.get or List.set at a computed index inside a def that calls itself, when the list is a fixed table: a literal, an array, or List.replicate / Array.new / List.range with a constant count, written inline, defined beside the loop, or held by the let of that name in scope. The index walks that table on every step. Keep it in an Array. A let reaches the statements after it and the blocks under them, not a sibling case arm, and a later let of the name to anything else ends it. A literal index (a fixed slot, including 0 and 1), a growing or data-dependent list, a one-shot outside the recursion, and List.head / List.tail do not run. index leaves a table this rule owns, so one call is one finding. Laws and proofs do not run (a def with no type at all fills a law: it is a proof).

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 ../calls.bend as Calls
import ../../lazy/lazy.bend as Lazy