~/bend-docscommunity

src/rules/correctness/strings.bend fails

raw source on the hub · import 0xde9bb08f7de298b03207fb5797ede9a5/src/rules/correctness/strings.bend as Strings

rule strings: a match whose arms are string literals (case "foo":) with more than 64 literal characters in all. Each string arm lowers into nested per-char tests, and the checker's time and memory grow with the characters (bend 2.0.16: 45 characters take 0.8 s and 0.35 GB, 100 take 2 s and 1 GB, 480 take 12 s and 4.8 GB; pi-bend BEND-001/016 was 16 long event names). The number of arms barely matters, so only the characters count. Classify the string once through a lookup table into a sum type, and match on that. Only a case's first match column is read: string literals in a later column of match a b: do not count. A literal with no closing quote (an unterminated string) is not a string arm.

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 ../tokens.bend as T