Apply @!override to constants instead of crashing the typechecker - #1305
Open
apiology wants to merge 1 commit into
Open
Apply @!override to constants instead of crashing the typechecker#1305apiology wants to merge 1 commit into
apiology wants to merge 1 commit into
Conversation
ApiMap::Index#redefine_return_type set the pin's @return_type and then unconditionally iterated pin.signatures. Only Pin::Method defines #signatures, so an @!override naming a constant (e.g. URI::DEFAULT_PARSER) raised NoMethodError from inside map_overrides and aborted the entire catalog/typecheck run with a traceback into Solargraph internals, with nothing pointing back at the annotation. Guard the signatures loop with a Pin::Method check. The @return_type assignment above it already does the right thing for a constant: Pin::Constant#return_type is `@return_type ||= generate_complex_type`, and neither Pin::Base#reset_generated! nor Pin::BaseVariable#reset_generated! clears @return_type, so the override sticks. map_overrides also adds the tag to the pin's docstring beforehand, which generate_complex_type would pick up on its own. So @!override now works on constants rather than merely not crashing, and any other non-method pin reaching this path degrades to setting just the return type instead of aborting the run. Fixes castwide#1302 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MEDQFCJ2M7gaYkUQVpiQzn
apiology
added a commit
to apiology/solargraph
that referenced
this pull request
Aug 16, 2026
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.
Fixes #1302.
Correcting a constant whose resolved type is wrong is a reasonable thing to want, and
@!overrideis the natural tool for it. Instead of being rejected or ignored, it aborted the whole typecheck with a traceback into Solargraph's internals, so nothing indicated that an annotation caused it:redefine_return_typeassumed every overridable pin responds to#signatures, which onlyPin::Methoddefines. This keeps the@return_typeassignment unconditional and guards just the signatures loop, so@!overridenow actually works on a constant rather than merely not crashing —Pin::Constant#return_typeis@return_type ||= generate_complex_type, and neitherPin::Base#reset_generated!norPin::BaseVariable#reset_generated!clears it, so the assignment sticks. Putting the guard here rather than inmap_overridesalso means any other non-method pin degrades to return-type-only instead of aborting the run.Verified against a local-constant repro (
FOO = 'bar'with# @!override FOO/@return [Integer]), which hits the identical line with the identical error before the change and resolves toIntegerafter. Note I did not reproduce the literalURI::DEFAULT_PARSERform from the issue — that path returned zero pins locally, sopath_pin_hash[ovr.name]was empty and it never reached the crash line; it needs stdlib RBS pins loaded.Specs: two unit specs in
spec/api_map/index_spec.rb(override on aPin::Constantdoesn't raise; return type becomesInteger) plus an end-to-end regression inspec/api_map_spec.rb. Full suite green locally: 1627 examples, 0 failures, 60 pending. RuboCop clean.Authored by Claude (Anthropic's Claude Code) on behalf of @apiology.