`self.private :foo` is reported as an invalid visibility call and ignored

Open
#1,085 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@RaphaelFakhri is already working on this.

Since Oct 25, 2026.

  • #1086 by @RaphaelFakhri — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby, rust

Research direction

Reproduce with the snippet in the issue body, then find the handler that emits InvalidMethodVisibility for private/protected/public/module_function. Compare with how include, prepend, extend, and private_constant already accept a self receiver, and make the visibility handlers do the same. Done looks like the expected Ruby 3.2 output: no diagnostics and the visibility/module-function applied.

Written by the indexing model from the issue text.

Description

Since Ruby 2.7, private methods can be called with a literal self receiver, so self.private :foo, self.protected, and self.module_function :foo behave the same as their receiverless forms. Rubydex rejects every receiver for private, protected, public, and module_function, including self. It reports an InvalidMethodVisibility diagnostic and does not apply the visibility.

Other handlers already treat self like an implicit receiver: include, prepend, extend, private_constant, and private_class_method.

Reproduction

class Foo
  def foo; end

  self.private :foo

  self.protected

  def bar; end
end

module Bar
  def baz; end

  self.module_function :baz
end

Ruby 3.2:

Foo.private_instance_methods(false)   # => [:foo]
Foo.protected_instance_methods(false) # => [:bar]
Bar.respond_to?(:baz)                 # => true

Expected

No diagnostics. foo is private, bar is protected, and Bar.baz is a module function.

Actual

Three diagnostics, for example InvalidMethodVisibility: `private` cannot be called with an explicit receiver. No MethodVisibility definitions are created, and bar stays public.

Dominant language
Rust
Stars
382
Forks
30
Avg merge
16h 57m
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Shopify/rubydex

All issues in Shopify/rubydex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.