Skip to content

language_standards.py: ABAP args regex misses !-prefixed params, mis-captures TYPE keyword #1917

Closed

Description

@squid-protocol

Summary

Found while investigating the tri-comparison chart's "Args Found" panel for abap (which turned out to be a separate, deeper problem than the file-level struct_args signal #1911 fixed). Two independent correctness bugs in ABAP's args regex (gitgalaxy/standards/language_standards.py):

"args": re.compile(
    r"\b(IMPORTING|EXPORTING|CHANGING|RETURNING|RECEIVING|EXCEPTIONS)\s+(?!TYPE\b)(?:VALUE\s*\([^)]*\)\s+)?[a-zA-Z_][a-zA-Z0-9_-]*",
    re.I,
),

1. The ! parameter-name escape prefix breaks matching entirely. ABAP uses a leading ! to escape formal parameter names (avoids a keyword collision) -- extremely common in real code:

CLASS-METHODS create_empty
  IMPORTING
    !ii_custom_mapping TYPE REF TO zif_abapgit_ajson_mapping OPTIONAL
    ...

[a-zA-Z_][a-zA-Z0-9_-]* doesn't include !, so when a clause's FIRST declared parameter uses this prefix, the whole clause fails to match at all -- finditer just skips past it looking for the next possible start position. Confirmed: zcl_abapgit_ajson.clas.abap's create_empty IMPORTING clause (4 real parameters) was entirely invisible to this regex because of this.

2. VALUE(...) is treated as an optional PREFIX before a still-mandatory trailing identifier, not as its own complete alternative -- so when a RETURNING/EXPORTING clause uses ABAP's VALUE(name) return-value syntax, the regex keeps matching past the closing ) into the next token:

>>> ABAP_RULES["args"].search("RETURNING VALUE(ro_instance) TYPE REF TO zcl_abapgit_ajson.").group(0)
'RETURNING VALUE(ro_instance) TYPE'

The literal word TYPE gets mis-captured as if it were a second parameter reference.

Impact

Both bugs affect the file-level struct_args signal too (not just per-function counting) -- bug 1 means any clause whose first parameter uses ! was silently invisible to struct_args, undercounting it further than #1911 alone fixed. Bug 2 doesn't change match COUNT but corrupts match CONTENT, which matters for anything downstream that reads the matched text (not just that a match occurred).

Fix

Restructure the trailing portion as a real alternation -- VALUE(...) OR a (now optionally !-prefixed) bare identifier, never both in sequence:

r"\b(IMPORTING|EXPORTING|CHANGING|RETURNING|RECEIVING|EXCEPTIONS)\s+(?!TYPE\b)"
r"(?:VALUE\s*\([^)]*\)|!?[a-zA-Z_][a-zA-Z0-9_-]*)"

Verified against every existing tests/extraction/languages/test_abap.py ARGS_* case (all still pass) plus two new regression cases for both bugs specifically.

Related

This is part of a broader investigation into why the tri-comparison chart's per-function "Args Found"/"Input Parameters" count is wrong for abap -- a separate follow-up issue covers the per-function search-span/counting mechanism itself (_calculate_block_metrics searches the wrong span and can't derive a real count from this regex's single-match-per-clause shape).

Activity

  1. added
    bug
    on Aug 20, 2026
  2. added this to the v2.4.9 milestone on Aug 31, 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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions