Skip to content

detector.py: ABAP class-scope-end brace search truncates on string-template braces, breaking method→class linkage #1907

Closed

Description

@squid-protocol

Summary

Found while verifying #1904's fix. Once #1904 makes ABAP's named classes list populate correctly, a second problem surfaces: method-to-class linkage (class_methods_by_id, which drives class_data.method_count/state_entanglement) is badly wrong for files containing ABAP's string-template syntax.

zcl_abapgit_objects.clas.abap has 30 real methods (struct_func_start/function_count both correctly show 30), but its class entry's method_count comes back as 2, not 30.

Root cause

splice()'s class-boundary resolution (detector.py ~line 799) calls _resolve_class_scope_end(), which tries a brace-delimited body search first (class_safe_stream.find("{", ...)) and only falls back to the flat "ends at the next class match" boundary if no { is found within 2000 chars. ABAP has no brace-delimited bodies at all (IMPLEMENTATION. ... ENDCLASS.), but it DOES have string-template interpolation syntax that legitimately contains {/}:

ii_log->add_success( iv_msg = |Object { is_item-obj_name } ...| ).

_build_brace_safe_stream() shields "/'/backtick-style string literals before the brace search runs, but has no knowledge of ABAP's |...| pipe-delimited string-template syntax, so this { is never shielded. The brace search finds it, treats it as if it opened the class's real body, and _find_balanced_end closes the "body" at the first coincidentally-balancing } -- truncating the class scope after only the first couple of methods. Every subsequent method in the file never gets linked to its class.

Suggested fix

Same shape as #1899's fix: ABAP classes are never nested (ABAP has no nested class definitions at all), so the existing flat "next class match, or EOF" fallback (fallback_end_idx, already computed unconditionally at the call site) is always correct for ABAP -- skip the brace-search path entirely for abap rather than trying to extend _build_brace_safe_stream to understand pipe-delimited string templates (a bigger, riskier change affecting other regex signals too, out of scope here).

Evidence

text = open("language-crucible/data/abap/abapGit/zcl_abapgit_objects.clas.abap", encoding="utf-8", errors="replace").read()
idx = text.find("CLASS zcl_abapgit_objects IMPLEMENTATION")
window = text[idx:idx+2000]
print(window.find("{"))  # 893 -- inside `|Object { is_item-obj_name }` string template, not a real body brace

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions