Fix a hang and a crash with omitted type arguments - #494
Merged
Merged
Conversation
When a type argument was not given (e.g., `class Sub < Gen` in Ruby for
`Gen[T]` in RBS), get_instance_type and similar places created a fresh
`Source.new` for it on every call. A box that typechecks against such a
type adds an edge from that vertex to itself, so each run produced a
different edge; ChangeSet#reinstall then added the new edge and removed
the old one, both of which re-queue the box, and the analysis never
terminated:
class Sub < Gen; end
accept(Sub.create) # accept: (Gen[Integer]) -> String
Use a single empty Source, GlobalEnv#untyped_arg, instead. An empty
Source neither holds nor propagates types, so sharing it among type
variables does not leak types between unrelated places, and the edges
and Instance types built from it stay the same across runs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A generic class or interface written without type arguments in RBS (e.g., `def gen: () -> Gen` for `Gen[T]`) made an Instance type with no arguments, and matching it against `Gen[Integer]` passed nil as the actual argument, which crashed with "undefined method 'each_type' for nil". Fill in the missing arguments with their default types or untyped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Found while reviewing #480.
Hang
get_instance_typeand similar places created a freshSource.newfor an omitted type argument on every call. When a box typechecks against such a type, it adds an edge from that vertex to itself, so each run adds a new edge and removes the old one. Both re-queue the box, and the analysis never terminates:This PR uses a single shared empty
Source(GlobalEnv#untyped_arg) instead. An emptySourceneither holds nor propagates types, so sharing it is safe.Crash
A generic type written without arguments in RBS (e.g.,
-> GenforGen[T]) produced anInstancewith no arguments. Matching it againstGen[Integer]crashed withundefined method 'each_type' for nil. The missing arguments are now filled in with their defaults or untyped.