You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
globals rule audit: 11 more languages share zig/dart's ^[ \t]* any-indentation anchor (#2651 follow-up) #2660
Follow-up from #2651 (zig+dart fixed there). During that fix I audited every language's globals rule for the same ^[ \t]* (any-indentation) anchor shape that let function-local var/const declarations count as globals. 11 more languages share the pattern:
Not all of these are necessarily bugs — some may have offsetting context (a keyword requiring package/file scope elsewhere in the alternation) or may simply have no realistic function-local collision in their morphology (css has no function scope at all, for instance). Each needs the same per-language check #2651 did: does an indented same-named construct exist in real code, and does it false-positive as a global?
Fix shape per language (where confirmed real): same anchor change as #2651, ^[ \t]* → ^(?![ \t]), with tests proving indented declarations don't count and top-level ones still do.
Found via keyword-rosetta classification / #2651's audit step.
Batch B.2 of #2669 — the per-language check this issue asks for, run on all 11.
Result: 1 of the 11 is a real bug with the #2651 fix shape. Applying the anchor change to the other 10 would break four languages and silently do nothing in four more.
Method, per language: (a) confirm the ^[ \t]* anchor is actually present in the rule; (b) hand-built scratch scan with a top-level construct that must keep counting and an indented same-named one; (c) run the current rule and the ^(?![ \t]) variant over the real-world language-crucible corpus and read what the change would actually delete. (c) is what decided most of these — the scratch scan alone would have got four of them wrong.
globals is at the planted 2 for all 11 in the rosetta corpus, so no rosetta cell can validate any of this; the crucible numbers below are the only evidence available, and they double as a preview of the golden-master diff.
^[ \t]*var\s+[a-zA-Z_]\w*\s*(?:[a-zA-Z_]\w*\s*)?=. gofmt indents function bodies with tabs, so every function-local var x = … counts as a global. All 7 deletions on the crucible corpus were checked by hand and every one is function-local:
go/kubernetes/kubelet.go:91 var certificateRenewFailure = compbasemetrics.NewCounter( <- inside a func, after an if/err block
go/kubernetes/csi_plugin.go:325 var migratedPlugins = map[string](func() bool){ <- inside a func
go/core/syscall_linux.go:693 var len _Socklen = SizeofSockaddrAny <- inside func Accept4
go/kubernetes/scheduler.go:610 var found = false
go/core/proc.go:5415 var status uint32 = _Grunnable
100% false-positive removal, no true positive lost. The grouped-var regression you would expect does not exist, because the inner lines of a var ( … ) block carry no var keyword and never matched this rule in the first place:
var ( -> now: ['var single =', 'var local =']
registry = … fixed: ['var single =']
limit = 10
)
⚠️ kotlin and scheme — real false positive, but ^(?![ \t]) is the wrong fix
Both have a genuine FP and a genuine indented true positive, and the column-0 anchor cannot tell them apart — it deletes both.
kotlin. One scratch file, three matches, and the fix keeps the wrong one:
classFoo {
companionobject {
constvalLIMIT=5<-THE idiomatic Kotlin global constant. FixDELETES it.
}
funf() {
valTIMEOUT=3000<- genuine FP. Fix correctly deletes it.
}
}
now=3 ['companion object', 'const val LIMIT =', 'val TIMEOUT ='] → fixed=1 ['companion object']. Net effect on real code: trades a rare FP (uppercase function-local val) for losing the single most common way Kotlin declares a global. A workable shape is to require const for the indented form and keep ^(?![ \t]) only for the bare val — needs its own issue and its own tests.
scheme. Indentation does not track scope in Scheme; the wrapping form does. Internal defines are a real FP:
(define (f x)
(definey 5) <- local binding, currently counts as a global
y)
But the dominant real-world idiom wraps a whole file in (let () …) or (library …), which indents every module-level define. In the crucible corpus:
file
col-0 (define
indented (define
cpnanopass.ss (Chez, whole file inside (let () …) at line 16)
0
682
io.ss
0
285
syntax.ss
318
341
schemify.rkt
9
119
Anchoring to column 0 takes two entire real files from 285 and 682 candidate globals to zero. −79.8% corpus-wide is not FP removal, it is the rule going blind on the commonest Scheme file layout.
css (−16.7%). Deletes :root, body and * nested inside @media blocks. Those are real global selectors. As this issue itself guessed, css has no function scope — but the conclusion is stronger than "no collision": the anchor is load-bearing against nesting and must stay.
lua (−10.6%). Deletes X =, A =, PANDOC_STATE = and friends. In Lua any unqualified assignment without local is a global at any indentation — an indented COUNTER = 0 inside a function is exactly the bug the rule exists to find. The fix would make the rule miss real globals.
perl (±0). Indented our $x inside a sub still declares a package variable, i.e. a global — true positive. Incidence in the crucible is 0 anyway (grep -cE '^[ \t]+our[ \t]+[$@%]' = 0 across 29 files).
❌ Not real — anchor inert or no incidence
cpp (±0 over 489 matches in 47 files). The rule's first alternative \b(extern|static(?!\s*assert)|thread_local|inline\s+constexpr)\b is unanchored and catches the same lines, so the anchored second alternative can never change a count. Provably inert. (Separately: cpp does count a function-local static int n = 0; as a global — but via alternative 1, so globals rule audit: 11 more languages share zig/dart's ^[ \t]* any-indentation anchor (#2651 follow-up) #2660's fix cannot touch it, and static storage duration is arguably a defensible read. Not this issue.)
dockerfile (±0). grep -cE '^[ \t]+ENV[ \t]' = 0 across 71 real Dockerfiles — nobody indents ENV. And where it does occur it is a real global env var, since Dockerfile has no scoping. No FP to fix.
haskell (0 → 0). The rule requires an IORef|TVar|MVar type signature within 200 chars of unsafePerformIO; it fires zero times across 12 real Haskell files. A where-bound instance is constructible (scratch scan confirms it matches and the anchor would suppress it) but the idiom is essentially always top-level with {-# NOINLINE #-}. The anchor change is provably safe here — Haskell's layout rule puts top-level bindings at column 0 — but it has no measurable effect. Not worth the diff.
❌ livecode — not in the family
Its globals rule is \b(global\s+|the\s+global|the\s+environment|the\s+platform|it)\b|\$ENV\b, compiled re.I|re.U — no ^[ \t]* anchor and not even re.M. It cannot have this defect. The audit list should read 10 languages, not 11.
Record assembly / css / lua / perl explicitly as audited, fix rejected on evidence, so no later sweep re-proposes the anchor change on them.
kotlin and scheme want their own issue — both are real defects that this fix shape cannot express. Not filed here: B.2's remit is triage, so that call is left to the next session.
assembly / css / lua / perl / cpp / dockerfile / haskell remain audited, fix rejected on evidence, and livecode is not in the family (no anchor). That leaves go as this issue's whole remaining scope.
Activity
squid-protocol commentedon Sep 2, 2026
Batch B.2 of #2669 — the per-language check this issue asks for, run on all 11.
Result: 1 of the 11 is a real bug with the #2651 fix shape. Applying the anchor change to the other 10 would break four languages and silently do nothing in four more.
Method, per language: (a) confirm the
^[ \t]*anchor is actually present in the rule; (b) hand-built scratch scan with a top-level construct that must keep counting and an indented same-named one; (c) run the current rule and the^(?![ \t])variant over the real-worldlanguage-cruciblecorpus and read what the change would actually delete. (c) is what decided most of these — the scratch scan alone would have got four of them wrong.globalsis at the planted 2 for all 11 in the rosetta corpus, so no rosetta cell can validate any of this; the crucible numbers below are the only evidence available, and they double as a preview of the golden-master diff.Verdict table
globalsnow → anchoredouris a global; 0 incidence✅ go — real, ship it
^[ \t]*var\s+[a-zA-Z_]\w*\s*(?:[a-zA-Z_]\w*\s*)?=. gofmt indents function bodies with tabs, so every function-localvar x = …counts as a global. All 7 deletions on the crucible corpus were checked by hand and every one is function-local:100% false-positive removal, no true positive lost. The grouped-
varregression you would expect does not exist, because the inner lines of avar ( … )block carry novarkeyword and never matched this rule in the first place:^(?![ \t])is the wrong fixBoth have a genuine FP and a genuine indented true positive, and the column-0 anchor cannot tell them apart — it deletes both.
kotlin. One scratch file, three matches, and the fix keeps the wrong one:
now=3 ['companion object', 'const val LIMIT =', 'val TIMEOUT ='] → fixed=1 ['companion object']. Net effect on real code: trades a rare FP (uppercase function-localval) for losing the single most common way Kotlin declares a global. A workable shape is to requireconstfor the indented form and keep^(?![ \t])only for the bareval— needs its own issue and its own tests.scheme. Indentation does not track scope in Scheme; the wrapping form does. Internal defines are a real FP:
But the dominant real-world idiom wraps a whole file in
(let () …)or(library …), which indents every module-level define. In the crucible corpus:(define(definecpnanopass.ss(Chez, whole file inside(let () …)at line 16)io.sssyntax.ssschemify.rktAnchoring to column 0 takes two entire real files from 285 and 682 candidate globals to zero. −79.8% corpus-wide is not FP removal, it is the rule going blind on the commonest Scheme file layout.
❌ Fix actively harmful — indentation is not scope
.data, 7.rodata, 5.bss, 2SECTION .data, 2SECTION .bss. GAS/NASM convention indents directives and only labels sit at column 0, so every one of those is a real global data section. This rule matches section directives, not variable declarations — it never had the zig + dart: globals rule anchors ^[ \t]* so function-local var/const count as globals (+150% on the rosetta corpus) #2651 defect.:root,bodyand*nested inside@mediablocks. Those are real global selectors. As this issue itself guessed, css has no function scope — but the conclusion is stronger than "no collision": the anchor is load-bearing against nesting and must stay.X =,A =,PANDOC_STATE =and friends. In Lua any unqualified assignment withoutlocalis a global at any indentation — an indentedCOUNTER = 0inside a function is exactly the bug the rule exists to find. The fix would make the rule miss real globals.our $xinside a sub still declares a package variable, i.e. a global — true positive. Incidence in the crucible is 0 anyway (grep -cE '^[ \t]+our[ \t]+[$@%]'= 0 across 29 files).❌ Not real — anchor inert or no incidence
\b(extern|static(?!\s*assert)|thread_local|inline\s+constexpr)\bis unanchored and catches the same lines, so the anchored second alternative can never change a count. Provably inert. (Separately: cpp does count a function-localstatic int n = 0;as a global — but via alternative 1, so globals rule audit: 11 more languages share zig/dart's ^[ \t]* any-indentation anchor (#2651 follow-up) #2660's fix cannot touch it, and static storage duration is arguably a defensible read. Not this issue.)grep -cE '^[ \t]+ENV[ \t]'= 0 across 71 real Dockerfiles — nobody indentsENV. And where it does occur it is a real global env var, since Dockerfile has no scoping. No FP to fix.IORef|TVar|MVartype signature within 200 chars ofunsafePerformIO; it fires zero times across 12 real Haskell files. Awhere-bound instance is constructible (scratch scan confirms it matches and the anchor would suppress it) but the idiom is essentially always top-level with{-# NOINLINE #-}. The anchor change is provably safe here — Haskell's layout rule puts top-level bindings at column 0 — but it has no measurable effect. Not worth the diff.❌ livecode — not in the family
Its
globalsrule is\b(global\s+|the\s+global|the\s+environment|the\s+platform|it)\b|\$ENV\b, compiledre.I|re.U— no^[ \t]*anchor and not evenre.M. It cannot have this defect. The audit list should read 10 languages, not 11.Recommendation
vardoesn't count, top-level does, groupedvar ( … )unaffected).squid-protocol commentedon Sep 2, 2026
Follow-up to the B.2 report above: the two "real FP, wrong fix shape" languages are now filed separately, so this issue can be narrowed to
goalone.const valin a companion object is a real global — the #2651 col-0 anchor deletes it along with the function-local false positive #2673 — kotlin. Discriminator is theconstmodifier, not the column: Kotlin permitsconst valonly at top level or in anobject/companion object, so it is always a global at any indentation, while a barevalis only a global at column 0. Validated against all six placement cases; neither corpus moves, so no rebless.assembly / css / lua / perl / cpp / dockerfile / haskell remain audited, fix rejected on evidence, and livecode is not in the family (no anchor). That leaves
goas this issue's whole remaining scope.chore(crucible): re-bless golden masters for the B.3 wave-1 regex batch
fix(core-engine): Rosetta batch 3 wave 1 — five registry-regex fixes …