Fix forward reference to Range in Hover causing load-time crash#911
Merged
Morriar merged 3 commits intoShopify:mainfrom May 8, 2026
Merged
Conversation
Spoom::LSP::Hover at line 16 declared const :range, T.nilable(Range), but Spoom::LSP::Range was defined later in the same file at line 73. At class-body evaluation time, Range resolved via lexical scope to Ruby's built-in ::Range, which sorbet-runtime auto-coerces to a T::Types::TypedRange. Computing the union hash later raised: Invalid value for type constraint. ... Got a NilClass. (T::Types::TypedRange#name -> T::Utils.coerce on nil element type) This made require 'spoom/sorbet/lsp' crash on load, which in turn broke 'tapioca init' and any CLI entry that touched Spoom::LSP. Fix: reorder so primitive structs (Position, Range, Location) are defined before composites that reference them (Hover). No behavior change, no type-info loss.
KaanOzkan
approved these changes
May 7, 2026
Contributor
KaanOzkan
left a comment
There was a problem hiding this comment.
Thanks, it just needs a bundle exec spoom srb sigs export to fix CI
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@KaanOzkan |
Morriar
approved these changes
May 8, 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.
Problem
Spoom::LSP::Hoverdeclaresconst :range, T.nilable(Range)at line 20 oflib/spoom/sorbet/lsp/structures.rb, butSpoom::LSP::Rangeis defined later in the same file at line 73.At class-body evaluation time, the bare
Rangeconstant resolves through Ruby's lexical scope:Spoom::LSP::Hover::Range— not definedSpoom::LSP::Range— not yet defined (it will be, at line 73)Spoom::Range— not defined::Range— Ruby's built-inRangeclass ✅ resolved hereSo
T.nilable(Range)is silently interpreted asT.nilable(::Range).sorbet-runtimeauto-coerces a bare::Rangeclass into aT::Types::TypedRangewhose element type isnil. When the union's hash is later computed at registration time, the chain blows up:This makes
require "spoom"raise on load, which in turn breaksbundle exec tapioca initand any CLI entry point that transitively touchesSpoom::LSP.Reproduction
The crash reproduces on both Ruby 3.3 and Ruby 4.0 with
sorbet-runtime 0.6.13196+spoom 1.7.13:$ docker run --rm ruby:3.3-slim bash -c \ 'gem install --no-document spoom -v 1.7.13 && \ ruby -e "require \"spoom\""' ... /usr/local/bundle/gems/sorbet-runtime-0.6.13196/lib/types/utils.rb:32:in `coerce_and_check_module_types': Invalid value for type constraint. ... Got a `NilClass`. (RuntimeError) ... from /usr/local/bundle/gems/spoom-1.7.13/lib/spoom/sorbet/lsp/structures.rb:20:in `<class:Hover>'Same stack trace on Ruby 4.0.3. I haven't bisected
sorbet-runtimeto find when the::Rangeauto-coercion started raising, but the spoom code has been relying on lexical-scope luck regardless.The bug appears not to be caught by CI presumably because no test path actually causes
require "spoom"to loadspoom/sorbet/lspend-to-end on a fresh Ruby process — but anything that goes throughbundle exec tapioca init(a common adoption path) hits it on first run.Fix
Move the
Hoverclass to be defined afterPositionandRange, soT.nilable(Range)resolves toSpoom::LSP::Rangeas intended.The diff is a pure reorder: 29 insertions, 29 deletions, no behavioral or API change.
Hover(line 16) →Position→Range→Location→ …Position→Range→Hover→Location→ …DocumentSymbol(which also referencesRangeandLocation) was already defined after them and continues to work.Relation to #841
#841 (migrating all
T::Structusages to bare Ruby classes) supersedes this patch — once it lands, theconst :range, T.nilable(Range)declaration disappears entirely and this whole class of bug goes away. I verified locally that #841 also resolves the crash.I'm submitting this as a smaller, lower-risk patch in case #841 takes longer to land, since the load-time crash is a hard blocker for adopting Sorbet through a downstream project today. Happy to close if you'd rather wait for #841.
Verification
mainrequire "spoom"loaded okbundle exec tapioca init+srb tcsrb tcreports no errorsExisting spoom tests should pass unchanged since this is a pure reorder.