fix(rewriter): preserve scoped nested renames - #339
Closed
fischeti wants to merge 2 commits into
Closed
Conversation
thommythomaso
approved these changes
Aug 3, 2026
Contributor
Author
|
Superseded by #342, which fixes this at the root instead of adding another manual re-walk. The underlying issue is that |
fischeti
added a commit
that referenced
this pull request
Aug 4, 2026
…ments Every rename the pickler performs is a single identifier token, but the rewriter was replacing whole syntax nodes via deepClone + replace(). In slang, replace() records a change keyed by the old node pointer and the tree cloner stops descending as soon as it hits one, so any change queued on a descendant is silently dropped. Nested scoped names therefore had to be re-walked by hand (rewrite_scoped_names_inplace) at every replacement site, which is easy to forget: the packed-dimension case in #338 was one such missed site, and VirtualInterfaceTypeSyntax and PackageImportItemSyntax were two more latent ones. Token changes are keyed by (owning node, child index) and are applied during the clone walk, so they compose with edits at any other depth. Switching every handler to replaceToken() plus an unconditional visitDefault() removes the whole category of bug rather than patching one more site, and lets rewrite_scoped_names_inplace and every deepClone go. Renaming a scoped name also no longer skips visitDefault, so the right subtree of a renamed scoped name is now visited. The regression test and fixtures are taken unchanged from #339, which this supersedes. Pickled output is byte-identical to before for the existing test project. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #338
Rewritting recursively with slang is a bit difficult with slang, since it does not persist for nested scoped names when replacing the syntax node. There is a helper function
rewrite_scoped_names_inplacewhich solves this, but it was simply missing for this particular case. I added some regression tests as well.