Skip to content

Reject TreeRewriter ranges from another source buffer - #1094

Open
OskarEichler wants to merge 1 commit into
whitequark:masterfrom
OskarEichler:codex/reject-foreign-tree-rewriter-ranges
Open

Reject TreeRewriter ranges from another source buffer#1094
OskarEichler wants to merge 1 commit into
whitequark:masterfrom
OskarEichler:codex/reject-foreign-tree-rewriter-ranges

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Reject rewrite actions whose Parser::Source::Range belongs to a different Source::Buffer.

Reproduction

target = Parser::Source::Buffer.new('(target)', source: 'alpha')
foreign = Parser::Source::Buffer.new('(foreign)', source: 'bravo')
rewriter = Parser::Source::TreeRewriter.new(target)
rewriter.replace(Parser::Source::Range.new(foreign, 0, 1), 'X')
puts rewriter.process # Xlpha

The offsets happen to fit, so the foreign range silently rewrites unrelated target bytes. Importing another rewriter already checks buffer identity; direct public rewrite actions should enforce the same invariant.

Verification

  • Packaged-runtime suite: 1,112 runs / 567,022 assertions, zero failures/errors/skips
  • Focused CLI/rewriter model: 14 checks, zero failures
  • Foreign-buffer model now raises ArgumentError; normal/import behavior remains covered by the full suite
  • 78 shipped Ruby/executable files are syntax-clean; downstream RuboCop inspects 4,195 files with no offenses

This is source-only and does not change valid same-buffer rewrites.

@marcandre

Copy link
Copy Markdown
Contributor

No objection, it could be better to be strict about this.

I'd add a test
I think the check in merge! would become redundant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants