Repository navigation
fix(kotlin): recognize expression-bodied and bodyless func_start bodies - #1413
Merged
Merged
Conversation
Add an `elif lang_id == "kotlin":` branch to `_slice_by_braces` (mirroring
scala's expression-body handling and rust's bodyless-declaration handling)
so kotlin's Mode-B body slicing stops silently dropping two idiomatic
shapes the generic fallback couldn't terminate:
- Expression-bodied functions (`fun f(): Int = 5`), bounded by
`next_match_start` since kotlin has no reliable statement terminator,
same as scala.
- Bodyless interface/abstract/expect declarations (`fun f(x: Int)` with no
`{`, `=`, or terminator at all) -- previously `continue`d and dropped
entirely; now accepted with the signature span itself as the (empty)
body.
The forward scan tracks `<>`/`()` depth so a `{` or `=` inside a generic
parameter list (e.g. `fun <T> f(x: T): Int = 5`) isn't mistaken for the
real terminator.
Fixes #1405.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Formatting: split the long elif condition in the new kotlin _slice_by_braces branch per ruff format's zero-tolerance line-length rule. Baselines: tree_sitter_accuracy_baseline_kotlin.json regenerated (func recall 39.1%->100.0%, precision 90.0%->95.8%, extra_functions unchanged at 1). Summary table in language_standards.py refreshed to match. Golden master (both full-precision and zero-dependency) regenerated: drift is expected and fully explainable -- kotlin/okhttp's own per-file metrics shift because 14 more real functions are now counted, plus small sympathetic 3D-coordinate ripple in unrelated tensorflow .td files from the shared PageRank-based spatial embedding recomputing globally. Confirmed no other language's function/class counts changed (isolated via a targeted diff of the crucible_check.py output before blessing). Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ssion-bodied-funcs # Conflicts: # tests/golden_master_audit.json # tests/golden_master_zero_dep_audit.json # tests/ruff_audit_baseline.json
…rigin/main ruby (#1406) and haskell (#1312) merged to main while this branch was open. Merged origin/main; the 3 machine-generated files (golden_master_audit.json, golden_master_zero_dep_audit.json, ruff_audit_baseline.json) conflicted on text but were stale either way, so took origin/main's version and regenerated fresh on the merged code instead of hand-resolving. Confirmed the fresh 17-difference drift is confined to kotlin/okhttp's own metrics plus expected coordinate ripple in unrelated files (td/, xml/) -- no other language's function/class counts changed. crucible_check.py and audit_check.py both clean after regeneration. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
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_braceshad no per-language branch (unlike csharp/scala/rust/objc), so it fell through to the generic brace-only path, which silently dropped two idiomatic, common Kotlin shapes: expression-bodied functions (fun f() = expr, no{) and bodyless interface/abstract method declarations (fun f(x: Int), no{, no=).lang_id == "kotlin"branch mirroring the scala (=-body, bounded by next match) and rust (bodyless-signature-accepted) precedents, with<>/()depth-tracking so generics and nested parens in the signature don't confuse the scan.Map<String, () -> Int>) -- traced through by hand and confirmed Kotlin's grammar never lets a real{/=appear while the tracked depth is spuriously wrong, so it's safe as written.Results
tree_sitter_accuracy_audit.py --lang kotlinagainstlanguage-crucible/data/kotlin/okhttp:extra_functionsunchanged at 1, a pre-existing unrelatedconstructorfalse positive)Golden master
Regenerated both fixtures (full-precision and zero-dependency). Drift is confined to kotlin/okhttp's own per-file metrics (14 more real functions now counted) plus small sympathetic 3D-coordinate ripple in unrelated files from the shared spatial embedding -- confirmed no other language's function/class counts changed.
Implemented by Gemini/agy (isolated worktree, root cause + fix shape pre-diagnosed in #1405), independently re-verified: diff reviewed line-by-line (including tracing the depth-tracking logic against adversarial generic/arrow cases by hand), all 133 kotlin tests re-run from scratch, accuracy audit re-run independently,
crucible_check.pyisolated and confirmed clean before blessing, ruff format/baseline issues found and fixed during review.Closes #1405.
Test plan
tests/extraction/languages/test_kotlin.py+test_kotlin_strict.py: 133 passedtree_sitter_accuracy_audit.py --lang kotlin: recall 39.1%->100.0%, no regressioncrucible_check.py: PASS (full-precision + zero-dependency) after golden master regenaudit_check.py: clean (ruff/mypy/dead-key/ast-accuracy all pass)🤖 Generated with Claude Code