Skip to content

feat(vba): detect statement-form calls after Then/Else in single-line If #45

Description

@ardelperal

Priority

P2 — dominant legacy error-handling idiom.

Context

Single-line If is everywhere in Access legacy code:

If Err.Number <> 0 Then GestionarError
If Not IsNull(x) Then ProcesarDato x, True Else LimpiarDato

Current behavior

detectStatementCall / detectQualifiedStatementCall (src/extraction/vba-extractor.ts ~1617 / ~1690) only inspect the start of the line. The leading identifier is If (blacklisted), so statement-form calls after Then / Else are silently dropped. Paren-form calls on the same line are caught by CALL_RE (it scans the whole line), which makes the gap inconsistent as well as lossy.

Expected behavior

Statement-form calls in the Then and Else clauses of a single-line If produce the same calls edges they would on their own line.

Implementation sketch

  • In the statement-call section of sweepCallsAndSql (~1353), when the masked line matches /^\s*If\b.*\bThen\s+(\S.*)$/i (i.e. something follows Then — a block If has nothing after it), split the remainder on a top-level Else (case-insensitive, not inside parens) and run detectStatementCall + detectQualifiedStatementCall on each clause.
  • Also handle colon-separated statements inside each clause (Then DoA: DoB) by splitting on : — colons cannot appear inside the masked string content.
  • Guard: Then GoTo label, Then Exit Sub, Then Resume Next, Then Err.Raise ... must not emit — GoTo, Exit, Resume need to be respected (add GoTo to CALL_KEYWORD_BLACKLIST if missing; Exit/Resume/Error are already there).
  • ElseIf lines are block-form (nothing to do).

Acceptance criteria

  • If x Then Foo emits calls → local Foo.
  • If x Then Foo Else Bar emits both edges.
  • If x Then obj.Metodo arg follows the qualified-call policy (gating per the qualified-call issue).
  • If x Then GoTo fin / Then Exit Sub emit nothing.
  • Multi-statement Then DoA: DoB emits both.

Validation

Index C:\Proyectos\dysflow\E2E_testing\src; count new same-file calls edges; sample for precision (no GoTo targets or keywords as callees).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vbaVBA/Access-specific work (parent codegraph product)enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions