Skip to content

lua: func_start misses a 'local function' that is not the first statement on its line #2461

Closed

Description

@squid-protocol

Summary

GitGalaxy's lua func_start is start-of-line anchored (^[ \t]*(?:local[ \t\n]+)?...function),
so a local function / function declaration preceded by another statement on the same line is
missed.

Repro

language-crucible/data/lua/cosmopolitan/constructs.lua:105:

local a; local function f(x) x={a=1}; x={x=1}; x={G=1} end

The local a; before local function f(x) means ^[ \t]*local[ \t]+function doesn't match.
GitGalaxy finds the other 4 function f in that file (lines 133/169/205/222), missing only this
one. tree-sitter-lua and ctags both find it. (lua func recall 99.7%, this is 1 of the 2 misses.)

Second, lower-value miss in the same audit

cosmopolitan/literals.lua:80 local function lexerror (s, err) — missed because the file
(test/literals.lua, the Lua test-suite's lexer torture fixture) contains adversarially
nested long-bracket strings ([==[[===[[=[]]=][====[]]===]===]====]) that defeat
_LUA_LONG_BRACKET_RE's single-\1-backref shielding, corrupting the segment lexerror sits
in. Only ever exercised by this one fixture; noting it here rather than a separate issue.

Fix direction

For the first case: also scan for func_start after a ; on a line, or drop the start-of-line
anchor for the local function / function forms (they're unambiguous keywords). Needs a
regression check against the existing function -as- Mode-D-opener keyword counting.

Found by

tri-comparison-ledger-sweep step 2.6 recall audit, 2026-08-29.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions