Skip to content

fix(lua): one-line functions, [[ ]] segmentation splits, class heuristic - #2444

Merged
squid-protocol merged 1 commit into
mainfrom
lua-followups-2438-2439-2440
Aug 29, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
lua-followups-2438-2439-2440

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Follow-on to #2441, closing three issues the lua tri-comparison sweep filed.

#2438 — one-line function declarations never emitted

A one-liner function a:x (x) return x+self.i end has an equal opener/closer count → net Mode-D
scope change ≤ 0, so the primary scan filed it as global dust and the function_opener pass
skipped it (depth_before_line[i] <= 0 gate). Affected plain names, redefinitions
(function deep (n) ... end), method heads, and every declaration nested in a bare do
block (do isn't a Mode-D opener). Fixed by extending function_opener to top-level
self-closing declarations, lua-scoped so ruby/matlab/livecode keep the strict gate. The
Anonymous_Block name-borrow fallback now skips a completed one-liner so an adjacent
coroutine.wrap(function() ... end) closure isn't mislabeled with the previous line's name.

(The issue's "dotted head" framing was a misdiagnosis — _extract_semantic_name already
resolves a.b.c.f1 / a:deep.)

#2440 — polyglot segmentation split a function at embedded markup

detector.py's _partition_segments scanned for ^\s*<style / ^\s*<script on raw text, so
the HTML inside Write([[<!doctype html> … <style> … ]]) in the redbean demo files
(fetch.lua, binarytrees.lua, maxmind.lua) was carved into a css segment mid-function,
producing a <name>_[Truncated] satellite. Fixed by scanning triggers against a view where lua
long-bracket literals are blanked to same-length filler (byte offsets and line numbers preserved;
segment slicing still uses the untouched text). Same mask added to prism's
_partition_embedded_languages.

#2439 — class_start heuristic matched ALL_CAPS data tables

Lua has no class keyword; the Name = { heuristic fired on local FISH = { ... }
(Game-of-Life patterns), local Arr = {}, one-letter test fixtures. Fixed by requiring a
proto-table tell — function Name[.:], Name.__index, setmetatable(…, Name), or Name[.:]new
— within a bounded window for the heuristic branch. The explicit ---@class (LuaLS annotation)
branch is never gated. Only tracegc.lua:M (a real module table with function M.start /
function M.stop / return M) survives.

Measured effect

tree_sitter_accuracy_audit.py --lang lua:

Metric Before (#2441 baseline) After
found_functions 557 618
extra_functions (lower better) 7 1
extra_classes (lower better) 14 1
args_exact_match 516 572

Lua recall 89.8% → 99.7%, function precision 98.8% → 99.8%.

Differential Scan

  • Both golden masters re-blessed — diff is lua files + directory-group summaries + topological
    coordinate ripple on a handful of unrelated files. crucible_check.py --mode both PASS.
  • tests/tree_sitter_accuracy_baseline_lua.json regenerated (--regenerate, all gated metrics
    improved). Summary table in language_standards.py updated.
  • tree_sitter_accuracy_audit.py --all --ci 31/31 OK. tri_comparison_chart.py --all --ci OK.
  • Full tests/extraction (6808) + tests/core_engine pass; ruby / matlab / livecode extraction
    (the other function_opener languages) unaffected. audit_check.py clean.
  • Ledger verdicts, chart, and points-of-interest regenerated (--all --write).
    docs/language_status/lua.md §9 updated (now documents 5 fixed defects across two PRs).

Residual

Not filed — one \z line-continuation inside a single-quoted string defeats the newline-bounded
literal shield (events.lua), a pre-existing cross-language gap and the last lua _[Truncated]
in the corpus. #2437 has no remaining lua repro.

Closes #2438, closes #2439, closes #2440.

🤖 Generated with Claude Code

https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S

Follow-on to #2441, closing three issues the lua tri-comparison sweep filed.

opener/closer count, so their net Mode-D scope change is <= 0: the primary
scan filed them as global dust and the `function_opener` pass skipped them
(`depth_before_line[i] <= 0` gate). Affected plain names, redefinitions,
method heads, and every declaration nested in a bare `do` block. Fixed by
extending `function_opener` to top-level self-closing declarations,
lua-scoped so ruby/matlab/livecode keep the strict gate. The
Anonymous_Block name-borrow fallback is taught to skip a completed
one-liner so an adjacent `coroutine.wrap(function() ... end)` closure
isn't mislabeled with the previous line's name. (The issue's "dotted head"
framing was a misdiagnosis -- `_extract_semantic_name` already resolves
`a.b.c.f1` / `a:deep`.)

raw text, so the HTML inside `Write([[<!doctype html> ... ]])` in redbean
demo files was carved into a `css` segment mid-function, producing a
`<name>_[Truncated]` satellite. Fixed by running the trigger scan against
a view where lua long-bracket literals are blanked to same-length filler
(offsets + line numbers preserved; segment slicing unchanged). Same mask
added to prism's `_partition_embedded_languages`.

tables (`local FISH = { ... }`, one-letter fixtures). Fixed by requiring a
proto-table tell -- `function Name[.:]`, `Name.__index`,
`setmetatable(..., Name)`, or `Name[.:]new` -- within a bounded window for
the heuristic branch; the explicit `---@class` branch is never gated.

Measured (`tree_sitter_accuracy_audit.py --lang lua`): found_functions
557 -> 618, extra_functions 7 -> 1, extra_classes 14 -> 1, args_exact_match
516 -> 572. Lua recall 89.8% -> 99.7%, precision 98.8% -> 99.8%. Both
golden masters re-blessed (lua files + topological ripple only), lua
baseline + summary table regenerated, ledger verdicts + chart +
points-of-interest regenerated (`--all`), `docs/language_status/lua.md` §9
updated.

One residual, not filed: a `\z` line-continuation inside a single-quoted
string defeats the newline-bounded literal shield (`events.lua`), a
pre-existing cross-language gap -- the last lua `_[Truncated]` in the
corpus. #2437 has no remaining lua repro.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 4e19b1e into main Aug 29, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the lua-followups-2438-2439-2440 branch August 29, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant