Give the RBS instance type its type arguments - #480
Open
sinsoku wants to merge 1 commit into
Open
Conversation
Type.default_param_map built the `*instance` entry with an empty argument
list, so a singleton method declared to return `instance` lost its type
arguments, and crashed when that result reached a type variable check
(SigTyVarNode#typecheck got nil instead of an actual argument). After
base_type the receiver is always an Instance or a Singleton, so
get_instance_type is always defined.
table = Hash[[["a", "b"]]] # Hash.[] is declared as `-> instance`
"foo".gsub(/o/, table) # gsub takes `hash[String, _ToS]`
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.
Motivation / Background
This Pull Request has been created because passing the result of
Hash[...]toString#gsubcrashes TypeProf:Hash.[]returnsinstance, butType.default_param_mapbuilt the*instanceentry with an empty argument list, so matching the result againstgsub's generichash[String, _ToS]left a type variable with no actual argument. ruby/ruby aborts onlib/cgi/escape.rbfor this reason.Detail
The fix delegates to
Type::Singleton#get_instance_type, which already fills the arguments in; afterbase_typethe receiver is always anInstanceor aSingleton, so it is always defined.instancenow prints with its type arguments, so a singleton method returning it reportsGen[untyped]where it used to reportGen, which is what an explicitGen[T]return type has always printed. The added scenario covers that output as well as the crash above.🤖 Generated with Claude Code