#441

`--replace-in-fn` doesn't decode inline `--new` escapes when `--old` matches verbatim

OpenU0001F3A2opened 24d ago

skill-data/graph.md:133 and docs/articles/cli-reference.md:146-147 say inline --old/--new accept \n escapes. --new is actually only decoded when the verbatim --old didn't match and the decoded one did (program_graph_patch_replace.c:98-123).

So a single-line --old with a multi-line --new fails (main @ 7e1a64d):

zero patch . --replace-in-fn pick --old 'let b: i32 = a + 2' --new 'let c: i32 = a + 2\n    let b: i32 = c'
program graph patch failed: replaceFunctionBody rows did not parse as a Zero function body
  expected: expression
  actual: row 2: let c: i32 = a + 2\n    let b: i32 = c

The same edit through --new-file works. Once decoding does apply, string escapes in --new get decoded too, so write("x\n") must be written write("x\\n") in that mode only.

scripts/snapshot-command-contracts.mts:4008-4032 covers verbatim replacement and decoded multi-line matching, but not this combination.

Documenting both rules (and pointing multi-line --new at --new-file -) or adding an explicit opt-in for decoding would fix it. Always decoding --new would break verbatim string literals.

Activity

0

No activity yet.