Skip to content

Conversation

@apiology
Copy link
Contributor

@apiology apiology commented Jul 14, 2025

Pending types for this class being added to the RBS repo and then to the RBS version the user has loaded, this will allow Gemfiles to be typechecked.

There are also fixes for various missing types needed for typechecking Solargraph.

Depends on #1056

apiology added 4 commits July 9, 2025 15:33
Drop rubygems as rbs collection won't let us shim core
Pending types for this class being added to the RBS repo and then to
the RBS version the user has loaded, this will allow Gemfiles to be
typechecked.
FileUtils.rm_rf path, secure: true
out.puts "Clearing pin cache in #{path}" unless out.nil?
else
out.puts "Pin cache file #{path} does not exist" unless out.nil?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful when debugging the core RBS fills!

end

FILLS_DIRECTORY = File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills')
FILLS_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicer to see an absolute path in log messages

def loader
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, we ended up with two identical methods here

@apiology apiology marked this pull request as draft July 14, 2025 16:38
# @param pin [Pin::Method]
# @return [Array<Problem>]
def method_param_type_problems_for pin
stack = api_map.get_method_stack(pin.namespace, pin.name, scope: pin.scope)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type checker changes were needed to make the test in gemfile_spec work. It turns out that the type checker was checking parameter types using the result of Pin::Method#parameters, which for RBS-loaded types is always an empty array.

I took the opportunity to refactor the 'first_param_hash' method into 'param_details_from_stack', which takes both the method pins from the stack as well as the particular signature we're testing against, which I think is more compatible with how it is used.

rooted: true, parameters_type: :list)
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin,
source: :rbs, type_location: type_location,
return_type: rest_positional_type,)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got into a bit of a yakshave here trying to get a test to pass, and found out that we don't preserve types for restargs from RBS.

fill_loader.add(path: Pathname(FILLS_DIRECTORY))
fill_conversions = Conversions.new(loader: fill_loader)
@pins.concat fill_conversions.pins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single EnvironmentLoader complains if it's given the same symbol twice - which could happen if one of our temporary fills like Bundler::Dsl is eventually adopted upstream (see ruby/rbs#2599). We'll get around that by using a separate loader for the fills, and deal with combining the duplicate pins downstream.

"Wrong argument type for Bundler::Dsl#source: source expected String, received Class<File>"].sort)
end

# @todo add rest arg support to type checker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cut the yakshave off here so the changes to type checker weren't more aggressive than they already are.

@apiology apiology marked this pull request as ready for review July 14, 2025 19:43
@apiology apiology changed the title Add RBS fill for Bundler::Dsl Add RBS fills and shims Jul 21, 2025
@apiology apiology changed the title Add RBS fills and shims Add RBS fills Jul 21, 2025
@castwide castwide merged commit 8aa00a8 into castwide:master Sep 30, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants