Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort_nodes! changes method privacy #141

Closed
mwudka opened this issue Dec 23, 2022 · 0 comments · Fixed by #142
Closed

sort_nodes! changes method privacy #141

mwudka opened this issue Dec 23, 2022 · 0 comments · Fixed by #142
Labels
bug Something isn't working

Comments

@mwudka
Copy link
Contributor

mwudka commented Dec 23, 2022

I think that the SortNodes rewriter doesn't preserve the position of private and protected, causing it to change the privacy of methods. For example, I would expect this input:

rbi = RBI::Tree.new
rbi << RBI::Method.new("c")
rbi << RBI::Private.new
rbi << RBI::Method.new("a")
rbi << RBI::Protected.new
rbi << RBI::Method.new("b")
rbi.sort_nodes!
puts rbi.string

to produce

def c; end
private
def a; end
protected
def b; end

but it sorts everything and produces

def a; end
def b; end
def c; end
private
protected

So that method b which should be private has become public, and c which should be protected is also public.

If my understanding is correct, the problem is in the node.nodes.sort! call in the SortNodes visitor, which currently sorts all the nodes. I think it needs to first segment the nodes into public, private, and protected ranges and sort those ranges individually. Would a PR to fix this be helpful?

@Morriar Morriar added the bug Something isn't working label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants