Skip to content

Releases: haproxytech/go-method-gen

Fix of field name inside the diff function

29 Apr 13:35

Choose a tag to compare

BUG: overhaul pointer diff generator with correct nil-delegation

The previous pointer template used a single code path for all sub-types,
hardcoding a key name ("NodeName" or "*SubType") and always looping with
"." concatenation. This produced wrong paths and panicked when the
inner type was itself a pointer.

Replace the single template with three distinct branches:

  • Builtin sub-node: nil cases return immediately with "" key; non-nil
    compares dereferenced values and emits "" — caller composes the path.
  • Inner-pointer sub-node (InnerDiffFuncName set): nil cases delegate
    directly to the inner standalone helper (passing nil is safe because
    the argument is a pointer); non-nil loops and prepends "." only when
    needed.
  • General (struct/slice/map): nil cases emit "" key and return; non-nil
    loops with smart separator guard.

Supporting data-model additions:
  • InnerDiffFuncNameMap constant — carries the standalone helper name
    for the inner sub-context when it is itself a pointer kind.
  • SubNodeKind field on Ctx — lets generators inspect the direct child
    kind without traversing SubCtxs.
  • GetTemplateDataFromSubNodeDiff now populates InnerDiffFuncName only
    when the single sub-context is a pointer with a non-trivial DiffFuncName.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>