Repository navigation
fix(prelude): Pathname#/ is an alias of #+, not a forwarding def - #766
Merged
Merged
Conversation
CRuby's pathname.rb writes `alias / +`. rbgo's prelude wrote
def /(other)
self + other
end
because the parser refused the alias: after `alias`, a `/` opened a regexp
instead of naming the division method. That is fixed in go-ruby-parser v0.11.1
(go-ruby-parser/parser#47), which this bumps to.
The workaround was not only a reflection difference. Three things diverged,
measured against ruby 4.0.5:
Pathname.instance_method(:/).original_name ruby :+ before :/
instance_method(:/) == instance_method(:+) ruby true before false
with #+ redefined, `Pathname.new("/a") / "b"`
ruby #<Pathname:/a/b>
before "HIJACKED"
The third is BEHAVIOUR: an alias keeps the body it was made from, while a
forwarding def follows whatever #+ later becomes. All three now match.
Measured: library/pathname/divide_spec.rb goes 0 -> 1, which is MRI's own
ceiling for it, and the spec is one example whose title is "is an alias of
Pathname#+" -- the corpus naming exactly this. The pathname library specs go
38 -> 39 overall with no file down. That suite is under library/, which the
ratchet does not sweep (only language/ and core/), so the gain is real but
ungated; nothing in language/ or core/ moves.
The prelude was the only site with this shape: a scan for an operator-named def
whose body just forwards to another operator found one, this one.
Closes nothing; enabled by go-ruby-parser/parser#47, which was itself found by
a README-claims test sweeping CI's Ruby 3.2 stdlib.
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.
What
CRuby's
pathname.rbwritesalias / +. rbgo's prelude wrote a forwarding definstead:
because the parser refused the alias: after
alias, a/opened a regexprather than naming the division method. Fixed in go-ruby-parser v0.11.1
(go-ruby-parser/parser#47), which this bumps to.
Measured — and it was not only a reflection difference
Pathname.instance_method(:/).original_name:+:/:+instance_method(:/) == instance_method(:+)truefalsetrue#+redefined,Pathname.new("/a") / "b"#<Pathname:/a/b>"HIJACKED"#<Pathname:/a/b>The third row is behaviour: an alias keeps the body it was made from, while
a forwarding def follows whatever
#+later becomes. That is the row that makesthis more than a tidy-up, and it is in the test.
Conformance
library/pathname/divide_spec.rbgoes 0 → 1, which is MRI's own ceiling forit. The file holds one example, and its title is "is an alias of Pathname#+" —
the corpus naming exactly this. The pathname library specs go 38 → 39 with
no file down.
That suite lives under
library/, which the ratchet does not sweep (onlylanguage/andcore/), so the gain is real but ungated — and nothing inlanguage/orcore/moves.Scope
A scan for the workaround's shape — an operator-named
defwhose body justforwards to another operator — found one site in the prelude, this one.
How it was found
A test written to pin the parser README's claims swept CI's stdlib. CI's runner
carries Ruby 3.2, not the 4.0.5 the project targets, so it swept 66 files
instead of 47 and refused
pathname.rbonalias / +— a construct valid inevery Ruby that no 4.0.5 top-level file happens to use. Fixing the lexer
upstream is what made this prelude change possible.
Green
go test ./... -count=1 -timeout=90mexit 0 (10 packages),gofmtclean,go vetclean,GOOS=wasip1andGOOS=jsclean. The frozen prelude wasregenerated, as its drift test requires.
🤖 Generated with Claude Code