Repository navigation
Fix nested functions being silently dropped from extraction (#1041) - #1045
Merged
Merged
Conversation
Mode B (_slice_by_braces) and Mode C (_slice_by_indentation) both skipped
any func_start match whose start fell before the previously accepted
match's end ("if start_idx < last_end_idx: continue"). A nested/inner
function declaration necessarily starts before its enclosing function's
end, so this guard silently dropped every nested function instead of
counting it as its own FunctionNode -- undercounting function_count and
merging the nested function's complexity into its parent's aggregate
metrics instead of reporting it separately.
The guard turns out to be unnecessary: each match already resolves its
own end independently (brace-depth tracking via _find_balanced_end for
Mode B, dedent tracking for Mode C), from its OWN start position -- so a
nested match already gets a correctly bounded, correctly nested scope on
its own once it's allowed to be processed at all. Removing the guard (and
the now-dead last_end_idx bookkeeping) is enough; no stack/depth tracker
needed on top of what the per-match boundary resolvers already do.
Mode A (labels/assembly) never had this guard and is unaffected.
Adds regression tests for both brace-style and indentation-style nested
functions, verifying the outer and inner functions are both extracted as
distinct FunctionNodes with independently correct scopes.
Closes #1041.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
#1041) Regenerated tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json via tests/tools/crucible_check.py --update against the language-crucible corpus, per the Differential Scan protocol. The prior commit (nested functions no longer silently dropped from extraction) intentionally changes structural output for any corpus file containing nested/inner functions or function expressions -- function counts, per-function complexity attribution, and every metric downstream of them (risk exposures, cluster assignments, cumulative mass/impact) shift accordingly across roughly 8,840 leaf values in each fixture. Spot- checked the diff for the failure modes that would actually indicate a bug rather than the intended fix: no tracebacks/exceptions, no crashes, and every composition/impact delta samples in the expected direction (more structure now counted, not less -- e.g. perl/mojo's cluster membership and total_mass both increase). Both full-precision and zero-dependency crucible_check.py runs are clean against the regenerated fixtures. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Owner
Author
|
Re-blessed the golden master fixtures against the language-crucible corpus ( |
…ions # Conflicts: # tests/golden_master_audit.json # tests/golden_master_zero_dep_audit.json # tests/ruff_audit_baseline.json
#1040 (nested class boundaries) merged to main after this branch's own golden master re-bless for #1041 (nested functions), so the merge above combined both fixes but carried a stale golden master that only reflected #1041 in isolation. Regenerated both fixtures via tests/tools/crucible_check.py --update against the language-crucible corpus so they reflect #1040 and #1041 together. The bulk of this delta is attributable to #1040 alone (already reviewed and merged separately) -- e.g. cpp/godot/object.h's bogus 464-line "initialize_class" function (the exact case called out in #1040's own PR description) drops out of the function list here because the class-scope fix now correctly consumes it as part of Object's class body instead of mis-parsing it as a giant standalone function. crucible_check.py passes clean in both full-precision and zero-dependency modes against the regenerated fixtures, with no tracebacks/exceptions in the diff. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_slice_by_braces) and Mode C (_slice_by_indentation) ingitgalaxy/core/detector.pyboth had an identical guard --if start_idx < last_end_idx: continue-- that skipped anyfunc_startmatch whose start fell before the previously accepted match's end. A nested/inner function declaration necessarily starts before its enclosing function's end, so this guard silently dropped every nested function instead of ever making it its ownFunctionNode(undercountingfunction_count, and merging the nested function's complexity into its parent's aggregate metrics instead of reporting it separately)._find_balanced_endfor Mode B, dedent tracking for Mode C) -- so once a nested match is allowed to be processed at all, it already gets a correctly bounded, correctly nested scope with no further changes needed. Removing the guard (and the now-deadlast_end_idxbookkeeping) is the whole fix.Verification
def-in-defand a brace-style nested function both collapsed to 1 extracted function instead of 2), confirmed fixed post-fix, including a sibling-nested-functions case (two inner defs at the same nesting depth under one outer function).test_detector_nested_function_is_counted_as_own_node_bracesandtest_detector_nested_function_is_counted_as_own_node_indentationintests/core_engine/test_detector.py.5435 passed, 2 skipped, 1 deselected, 11 xfailed, 3 xpassed.tests/tools/audit_check.py --regenerate: ruff baseline updated for 2 pure line-shift findings from the removed dead code (no new findings); mypy and dead-key audits clean.Note for reviewers
This is a parsing-logic change to
detector.py, so per the repo's Differential Scan protocol it should be checked againsttests/golden_master_audit.json/tests/golden_master_zero_dep_audit.jsonby CI'scrucible-auditcheck against the ~80-repo corpus. I don't haveLANGUAGE_CRUCIBLE_PATHset up locally, so I did not runcrucible_check.py-- deferring to CI here per the repo's cost-conscious-verification convention. Function counts are expected to increase for any corpus file with nested/inner functions (that's the intended fix), so ifcrucible-auditflags a diff, it should be reviewed and the golden master re-blessed viaupdate_golden_master.pyrather than treated as a regression by default -- happy to do that once CI reports the actual diff.Test plan
pytest tests/core_engine/test_detector.py -q-- 82 passedpytest tests/ -q-- full suite greentests/tools/audit_check.py-- clean after baseline regencrucible-audit-- pending, may require golden master re-bless (see note above)🤖 Generated with Claude Code