Skip to content

fix(kotlin): recognize expression-bodied and bodyless func_start bodies - #1413

Merged
squid-protocol merged 4 commits into
mainfrom
fix/kotlin-1405-expression-bodied-funcs
Aug 13, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
fix/kotlin-1405-expression-bodied-funcs

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • kotlin's _slice_by_braces had 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 =).
  • Added a 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.
  • Reviewed the depth-tracking against several adversarial cases (arrows inside generic return types like 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 kotlin against language-crucible/data/kotlin/okhttp:

  • func recall: 39.1% -> 100.0% (9/23 -> 23/23 real functions found)
  • func precision: 90.0% -> 95.8% (extra_functions unchanged at 1, a pre-existing unrelated constructor false positive)
  • args_exact_match: 9/9 -> 23/23

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.py isolated 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 passed
  • tree_sitter_accuracy_audit.py --lang kotlin: recall 39.1%->100.0%, no regression
  • crucible_check.py: PASS (full-precision + zero-dependency) after golden master regen
  • audit_check.py: clean (ruff/mypy/dead-key/ast-accuracy all pass)

🤖 Generated with Claude Code

squid-protocol and others added 4 commits August 12, 2026 21:38
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]>
@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 c75310a into main Aug 13, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/kotlin-1405-expression-bodied-funcs branch August 13, 2026 02:29
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.

kotlin func_start misses expression-bodied and bodyless interface method declarations (39.1% recall)

1 participant