Skip to content

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

Closed

Description

@squid-protocol

What

tests/tree_sitter_accuracy_baseline_kotlin.json shows kotlin func_start recall at only 39.1% (9 found / 23 real functions, per tree_sitter_accuracy_audit.py --lang kotlin against the language-crucible/data/kotlin/okhttp corpus). This number is trustworthy -- it comes after #1315 (merged 2026-08-12) fixed a prior measurement-tool bug that had been reporting kotlin's real_functions as 0. #1315 explicitly did not address the actual extraction gap, only the measurement bug masking it.

Evidence

gitgalaxy/core/detector.py's _slice_by_braces method (used for kotlin's Mode-B function-body slicing) has explicit per-language branches for csharp (~line 2034), scala (~line 2070), rust (~line 2104), and objective-c (~lines 2134, 2174) that each handle language-specific "how does a function body actually terminate" quirks -- but kotlin has no such branch, so it falls through to the generic else at ~line 2192, which does a blind forward search for the next { and silently drops matches (continue) if none is found before the search window closes.

This drops two common, idiomatic Kotlin shapes:

  1. Expression-bodied functions: fun executed(call: RealCall) = runningSyncCalls.add(call), fun queuedCallsCount(): Int = readyAsyncCalls.size -- no { at all, body is a bare = expr.
  2. Bodyless interface/abstract method declarations: fun enqueue(responseCallback: Callback), fun cancel(), fun addEventListener(eventListener: EventListener) -- no {, no =, no ; terminator; the signature just ends at the newline.

Real corpus confirmation (language-crucible/data/kotlin/okhttp):

  • Call.kt lines 69, 72, 102 -- bodyless interface method declarations (case 2 above)
  • Dispatcher.kt lines 265, 286, 297 -- expression-bodied functions (case 1 above)
  • Both shapes together account for at least 6 of the 14 missing real functions

Suggested fix shape

Add a new elif lang_id == "kotlin": branch in _slice_by_braces (mirroring the scala and rust branches immediately above it), after locating the parameter list's balanced closing ): scan forward for whichever of { (real block body -- use _find_balanced_end same as the generic path) or = (expression body -- like scala, kotlin has no reliable terminator character for this, so bound by next_match_start) comes first. If neither appears before the search window/next match, this is a legitimate bodyless interface/abstract/expect declaration (case 2) -- do NOT continue/drop it (that is the current bug); accept it with the signature span itself as the body (similar to how rust/objc accept ;-terminated bodyless trait methods, except kotlin has no terminator character at all).

Verify against the real language-crucible corpus using tree_sitter_accuracy_audit.py --lang kotlin to confirm recall improves without regressing precision (currently 90.0%) or extra_functions (currently 1).

Related

#1261 (parent epic), #1315 (fixed the measurement-tool bug masking this), #1266/#1319/#1314 (csharp/rust/objc precedents).

Activity

  1. added
    bug
    testing
    core-engine
    on Aug 13, 2026
  2. added a commit that references this issue on Aug 13, 2026
    c75310a
  3. added this to the v2.4.8 milestone on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginetesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions