Skip to content

undefined method `flat_map' for nil in bundler/spec_set.rb:143 (regression in 2.6) #8338

@swiknaba

Description

@swiknaba

Describe the problem as clearly as you can

ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/spec_set.rb:143:in `missing_specs': undefined method `flat_map' for nil (NoMethodError)

I get this error when using bundler 2.6.1. However, I cannot reproduce it using bundler 2.5.x.

Did you try upgrading rubygems & bundler?

This seems to be a regression in Bundler 2.6.x.

downgrading solves the issue, upgrading introduces it.

Post steps to reproduce the problem

  • using ruby 3.3.x (all stable versions tested)
  • using bundler 2.5.x vs. 2.6.x
  • using Sorbet & Tapioca

Set up a new app (e.g. use rails 6, 7, or 8, but can be a vanilla Ruby app for this issue).
Add Sorbet & Tapioca, then generate types for gems using:

bundle exec tapioca gem

or

bundle exec tapioca init

See exception being raised:

bundler/spec_set.rb:143:in `missing_specs': undefined method `flat_map' for nil

Minimal Gemfile to reproduce:

source "https://rubygems.org"

ruby "3.3.6"

gem "sorbet-runtime"
gem "sorbet"
gem "spoom"
gem "tapioca"

gem "bundler" # 2.5. / 2.6

Which command did you run?

Using Ruby 3.3.6 (also tested on Ruby 3.3.5):

rails _7.2_ new . --api

add Sorbet & Tapioca.

then:

bundle exec tapioca init

fails with

bundler/spec_set.rb:143:in `missing_specs': undefined method `flat_map' for nil

when using bundler 2.6.x, but succeeds with bundler 2.5.x.

What were you expecting to happen?

I expect the command to succeed :D

What actually happened?

stack trace:

(/Users/lr/.gem/ruby/3.3.6/bin/tapioca)
/Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/spec_set.rb:143:in `missing_specs': undefined method `flat_map' for nil (NoMethodError)

      @materializations.flat_map(&:completely_missing_specs)
                       ^^^^^^^^^
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/gemfile.rb:71:in `materialize_deps'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/gemfile.rb:58:in `load_dependencies'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/gemfile.rb:33:in `initialize'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/commands/abstract_gem.rb:65:in `new'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/commands/abstract_gem.rb:65:in `initialize'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/abstract/declare.rb:37:in `new'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/abstract/declare.rb:37:in `block in declare_abstract'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/abstract/declare.rb:37:in `block in declare_abstract'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/cli.rb:310:in `gem'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/invocation.rb:116:in `invoke'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/cli.rb:32:in `block in init'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/runtime/trackers.rb:26:in `with_trackers_enabled'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/lr/.gem/ruby/3.3.6/gems/sorbet-runtime-0.5.11704/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/lib/tapioca/cli.rb:29:in `init'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
	from /Users/lr/.gem/ruby/3.3.6/gems/thor-1.3.2/lib/thor/base.rb:584:in `start'
	from /Users/lr/.gem/ruby/3.3.6/gems/tapioca-0.16.5/exe/tapioca:30:in `<top (required)>'
	from /Users/lr/.gem/ruby/3.3.6/bin/tapioca:25:in `load'
	from /Users/lr/.gem/ruby/3.3.6/bin/tapioca:25:in `<top (required)>'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:59:in `load'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:59:in `kernel_load'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:23:in `run'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:452:in `exec'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:538:in `dispatch'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:35:in `dispatch'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:29:in `start'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/gems/3.3.0/gems/bundler-2.6.1/exe/bundle:28:in `block in <top (required)>'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/site_ruby/3.3.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/lr/.rubies/ruby-3.3.6/lib/ruby/gems/3.3.0/gems/bundler-2.6.1/exe/bundle:20:in `<top (required)>'
	from /Users/lr/.gem/ruby/3.3.6/bin/bundle:25:in `load'
	from /Users/lr/.gem/ruby/3.3.6/bin/bundle:25:in `<main>'

If not included with the output of your command, run bundle env and paste the output below

WORKING

Bundler 2.5.23
Platforms ruby, arm64-darwin-23
Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0) [arm64-darwin-23]
Full Path /Users/lr/.rubies/ruby-3.3.6/bin/ruby
Config Dir /Users/lr/.rubies/ruby-3.3.6/etc
RubyGems 3.6.1
Gem Home /Users/lr/.gem/ruby/3.3.6
Gem Path /Users/lr/.gem/ruby/3.3.6:/Users/lr/.rubies/ruby-3.3.6/lib/ruby/gems/3.3.0
User Home /Users/lr
User Path /Users/lr/.gem/ruby/3.3.0
Bin Dir /Users/lr/.gem/ruby/3.3.6/bin
Tools
Git 2.39.5 (Apple Git-154)
RVM not installed
rbenv not installed
chruby 0.3.9

FAILING

Bundler 2.6.1
Platforms ruby, arm64-darwin-23
Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0) [arm64-darwin-23]
Full Path /Users/lr/.rubies/ruby-3.3.6/bin/ruby
Config Dir /Users/lr/.rubies/ruby-3.3.6/etc
RubyGems 3.6.1
Gem Home /Users/lr/.gem/ruby/3.3.6
Gem Path /Users/lr/.gem/ruby/3.3.6:/Users/lr/.rubies/ruby-3.3.6/lib/ruby/gems/3.3.0
User Home /Users/lr
User Path /Users/lr/.gem/ruby/3.3.0
Bin Dir /Users/lr/.gem/ruby/3.3.6/bin
Tools
Git 2.39.5 (Apple Git-154)
RVM not installed
rbenv not installed
chruby 0.3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions