Skip to content

Analyse static functions, and stop merging them into the function above - #21

Open
rganz wants to merge 1 commit into
graydwarf:mainfrom
rganz:fix/static-func-boundary
Open

rganz wants to merge 1 commit into
graydwarf:mainfrom
rganz:fix/static-func-boundary

Conversation

@rganz

@rganz rganz commented Sep 14, 2026

Copy link
Copy Markdown

Fixes the two symptoms reported in #17.

_analyze_functions opened a new function only on begins_with("func "), which a static declaration does not match, so the static function was never analysed and its body was appended to the function above it. Normalising a leading static before the test fixes both and keeps the substr(5) assumption in _parse_function_signature valid.

Measured on a probe project against this tree, a two line function followed by an eight line static function:

before after
the small function reported at 12 lines not reported
the static function not reported at all reported at its own 9 lines

ignore-handler.gd and strict-handler.gd decide their own ranges the same way and have the same blind spot for a static func boundary. This change leaves them alone so the diff stays in one file; happy to follow up if you would like them in the same shape.

Same root as #15: the parser decides what a declaration is from the text of one line, so an annotation breaks it there and static breaks it here.

_analyze_functions opened a new function only on begins_with("func "), which a
static declaration does not match. Two things followed from that single test.

The static function was never analysed, so no length, parameter, nesting,
complexity or return type check ever saw it.

Its body was appended to the function above, because the parser was still
inside that one, inflating that function's reported length and complexity.

Normalising a leading "static " before the test keeps the substr(5) assumption
in _parse_function_signature valid and fixes both.

Measured on a probe project against this tree. A two line function followed by
an eight line static function was reported at 12 lines and is now not reported
at all; the static function was reported not at all and is now reported at its
own 9 lines.

Same root as the open report about annotations in front of a declaration: the
parser decides what a declaration is from the text of one line. ignore-handler
and strict-handler have the same blind spot for their own ranges, which this
commit deliberately leaves alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant