rewrite-clj
rewrite-clj copied to clipboard
`paredit/kill` and `global-find-by-node` work incorrectly
Version
rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}
Platform
Clojure version: 1.11.1
Symptom Two issues:
- When using
rewrite-clj.paredit/killincorrectly positions the zipper after performing the operation. - Docstring says that it should be removing nodes to the right from the current node. But in fact it deletes nodes starting from the current node.
Reproduction
(-> (z/of-string "[1 2 3 4]")
z/down
(z/insert-left (n/keyword-node :wrong-pos))
z/next
(z/insert-left (n/keyword-node :nil-meta))
pe/kill
z/print)
:wrong-pos
Actual behavior
- Positions zipper on the
:wrong-pos. - End result is
[:wrong-pos 1 :nil-meta ].
Expected behavior
- Expected to position on
2. - Expected end result is
[:wrong-pos 1 :nil-meta 2]
Diagnosis
- Incorrect positioning is caused by
global-find-by-nodesearch that compares nodes meta not taking into account that new nodes havenilmeta. - Either docstring or the behavior needs to be fixed to match each other.
Action Let me know if a PR is preferred.
Thanks @mrkam2!
I can take a peek sometime soon!
I'm starting to take a look at this one!
- I confirm that the kill docstring is wrong and the behavior is correct, barring the new node bug you found.
- I confirm that kill behavior is broken when new nodes are involved.
- And yes, anything that uses paredit API's internal
global-find-by-nodewill be broken for newly added nodes.
Thanks again for reporting, @mrkam2. Folks seem to be starting to use the paredit API a bit, and you've uncovered some very interesting flaws.