Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: already initialized constant StringScanner::Version #102

Closed
dabroz opened this issue May 31, 2024 · 11 comments
Closed

warning: already initialized constant StringScanner::Version #102

dabroz opened this issue May 31, 2024 · 11 comments

Comments

@dabroz
Copy link

dabroz commented May 31, 2024

When using this gem with ruby 3.3.1 I'm getting

.../.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/strscan-3.1.0/lib/strscan.bundle: warning: already initialized constant StringScanner::Version
@kou
Copy link
Member

kou commented May 31, 2024

Could you provide a way to reproduce this?

@kinsomicrote
Copy link

I am also seeing the same thing on my Rails project:

.../.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/strscan-3.1.0/lib/strscan.bundle: warning: already initialized constant StringScanner::Version
.../.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/strscan-3.1.0/lib/strscan.bundle: warning: already initialized constant StringScanner::Id

I get this when I run my test suite - rspec.
In my Rails project, strscan is used by rexml which is used by rubocop.

@dabroz
Copy link
Author

dabroz commented Jun 1, 2024

I've created a minified version of the project here: https://github.com/dabroz/strscantest
To see this behaviour, clone the repo, then run bundle; rspec test.rb
There is also a Dockerfile you can test wit h./dockme

But the strangest thing is that there have to be very specific circumstances to observe this problem:

  • only with Ruby 3.3
  • only directly on Mac, not on Linux via Docker
  • only when using bootsnap
  • only when using rbenv
  • only when running rspec via shim (when running bundle exec rspec it works fine)

@kou
Copy link
Member

kou commented Jun 1, 2024

Thanks for preparing a minified project.

Why do you want to use rspec not bundle exec rspec?
In general, you should use bundle exec ... when you use Gemfile to manage your dependency.

@dabroz
Copy link
Author

dabroz commented Jun 1, 2024

Overall sure, but this happens even on a clean rbenv install, where only gems are the ones installed from the Gemfile.

@kou
Copy link
Member

kou commented Jun 1, 2024

Could you show gem list output on the reproduced environment?

@dabroz
Copy link
Author

dabroz commented Jun 2, 2024

Bingo!

strscan (3.1.0, default: 3.0.7)

After pinning it:

gem 'strscan', '3.0.7'

it doesn't show the warning anymore. I had to pin rubocop to an earlier version (1.63.0) as the latest requires the latest strscan:

    rubocop was resolved to 1.64.0, which depends on
      rexml (>= 3.2.5, < 4.0) was resolved to 3.2.8, which depends on
        strscan (>= 3.0.9)

So can we do anything if a newer version of a default gem is needed?

@kou
Copy link
Member

kou commented Jun 2, 2024

The next REXML version that includes ruby/rexml#132 will change the situation. It relaxes required strscan version.
(But bundle exec rspec is still preferred.)

@Soeren-Klatt
Copy link

Got the same message when running only rspec without bundle exec. The message appeared after going from ruby 3.1.6 to ruby 3.2.0.
Im using strscan (3.1.0)

@kou
Copy link
Member

kou commented Jul 11, 2024

If gem list | grep strscan has multiple versions, you must use bundle exec to choose only one strscan.

@kou
Copy link
Member

kou commented Dec 12, 2024

This is not a strscan problem.

@kou kou closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants