Resolve retroactive singleton method visibility changes#781
Merged
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced May 5, 2026
299b305 to
0196acc
Compare
0196acc to
4ee8994
Compare
st0012
reviewed
May 7, 2026
vinistock
approved these changes
May 7, 2026
4ee8994 to
e8bbe37
Compare
16d134d to
27da4dd
Compare
e8bbe37 to
dd97c9f
Compare
27da4dd to
ce07ec6
Compare
dd97c9f to
c2e1a87
Compare
c2e1a87 to
7501d0a
Compare
7501d0a to
94a1a2f
Compare
Contributor
Author
Merge activity
|
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.

Part of #89 and follows #780, which added the
SINGLETON_METHOD_VISIBILITYbit flag and indexed singleton-flaggedMethodVisibilityDefinitions.This PR routes singleton-flagged defs through the singleton class and folds the singleton path into the existing
resolve_method_visibilitiespass. Visibility definitions are processed after the main convergence loop, so the target method declaration is guaranteed to exist by the time we attach visibility.For inherited targets like
private_class_method :foowherefoocomes from a parent class's singleton, we create a child-ownedMethodDeclarationon the child's singleton class. This matches what #738 did for instance methods, and what Ruby reports when you askChild.singleton_class.instance_method(:foo).owner:Why document-scoped diagnostics for the singleton path
When a singleton target doesn't resolve, the diagnostic attaches to the document, not to the singleton declaration. Walking ancestors via
get_or_create_singleton_class(Foo, ...)can synthesizeFoo::<Foo>as a side effect, even when it has no real members. Forclass Foo; private_class_method :missing; endwhereFoohas no other singleton methods, that synthetic singleton class only exists to host the diagnostic. Attaching to it would leak the declaration on file delete. Document-scoped clears with the file. Instance-method diagnostics keep their existing declaration scope: their owner can't be synthetic.Source-order processing of visibility defs
Ruby applies visibility statements in the order they appear in source, so the later one wins:
This was already broken on
mainfor instance methods; surfaced while wiring up the singleton path, fixed here for both.prepare_unitssorteddefinitionsandconst_refsby(uri_id, offset)for determinism but leftothers(which holds the visibility defs queued byhandle_remaining_definitions) inIdentityHashMapiteration order, which is bucket-hash order. SoFoo#barcould end upPrivatebecause the resolver happened to applypublicfirst andprivatesecond. Same sort applied toothersso the override-order invariant holds for both instance and singleton paths.In this PR
is_singleton_method_visibility()insideresolve_method_visibilities: resolve throughget_or_create_singleton_classfor the singleton path, render"class method"vs"method"in the diagnostic, attach document-scoped (singleton) vs declaration-scoped (instance)Graph::find_singleton_method_visibility_declarationand route through it from the existingDefinition::MethodVisibilityarm indefinition_to_declaration_idwhen the flag is setothersby(uri_id, offset)inprepare_unitsso visibility overrides apply in source order