Skip to content

Index private_class_method / public_class_method calls#780

Open
alexcrocha wants to merge 1 commit intomainfrom
05-04-index_private_class_method___public_class_method_calls
Open

Index private_class_method / public_class_method calls#780
alexcrocha wants to merge 1 commit intomainfrom
05-04-index_private_class_method___public_class_method_calls

Conversation

@alexcrocha
Copy link
Copy Markdown
Contributor

@alexcrocha alexcrocha commented May 5, 2026

Part of #89

This PR adds indexer support for private_class_method and public_class_method calls. Each call becomes a SingletonMethodVisibilityDefinition that the resolver applies to the singleton method declaration in a follow-up PR. This is the base of a Graphite stack.

We need a definition because the indexer can't yet attach the visibility change to the singleton method:

class Foo
  def self.bar; end
  private_class_method :bar
end

The method declaration for Foo::<Foo>#bar() only exists after resolution.

Why a new definition type

I made it a separate type rather than adding a receiver field to MethodVisibilityDefinition. Foo.private_class_method :bar accepts an explicit receiver, but private / protected / public don't, so MethodVisibilityDefinition has no receiver field today. Adding receiver: Option<NameId> to the existing type would cost every call site. Constant visibility made the same split.

In this PR

  • add Definition::SingletonMethodVisibility and SingletonMethodVisibilityDefinition
  • expose the new kind through the Rust / C / Ruby definition APIs
  • index private_class_method / public_class_method calls with literal symbol or string targets, with or without an explicit constant receiver
  • diagnose top-level calls, dynamic receivers, and non-literal arguments

Not in this PR

A few things are intentionally deferred to follow-up PRs in the stack:

  • extracting the receiver-validation and literal-extraction helpers we duplicate from handle_constant_visibility
  • supporting array arguments (private_class_method [:a, :b])
  • supporting inline-def arguments (private_class_method def self.foo; end)

Copy link
Copy Markdown
Contributor Author

alexcrocha commented May 5, 2026

@alexcrocha alexcrocha self-assigned this May 5, 2026
@alexcrocha alexcrocha added the enhancement New feature or request label May 5, 2026
@alexcrocha alexcrocha marked this pull request as ready for review May 5, 2026 21:50
@alexcrocha alexcrocha requested a review from a team as a code owner May 5, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant