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

Fix block being passed to __dry_initializer_initialize__ #109

Closed
bkuhlmann opened this issue Dec 28, 2024 · 5 comments
Closed

Fix block being passed to __dry_initializer_initialize__ #109

bkuhlmann opened this issue Dec 28, 2024 · 5 comments

Comments

@bkuhlmann
Copy link

bkuhlmann commented Dec 28, 2024

Describe the bug

Hello. 👋 I'm getting multiple warnings in my console when using Dry Initializer due to a block being passed to __dry_initializer_initialize__ when it shouldn't.

This is showing up because Ruby 2.4.1 issues warnings when you pass a block that isn't used. See Feature #15554.

To Reproduce

I don't have a great way, at the moment, to reproduce this since the warning seems to be indirectly triggered via Dry Schema because I'm not requiring Dry Initializer directly. Regardless, you'll want to ensure the following is enabled for your environment:

export RUBYOPT="-w -W:deprecated -W:performance -W:experimental"

I would expect the Dry Initializer test suite to be issuing these warnings too if warnings are enabled?

Expected behavior

I'd expect to not see this warning show up:

/Users/bkuhlmann/.cache/frum/versions/3.4.1/lib/ruby/gems/3.4.0/gems/dry-initializer-3.1.1/lib/dry/initializer/mixin/root.rb:11: warning: the block passed to '__dry_initializer_initialize__' defined at (eval at /Users/bkuhlmann/.cache/frum/versions/3.4.1/lib/ruby/gems/3.4.0/gems/dry-initializer-3.1.1/lib/dry/initializer/config.rb:112):2 may be ignored

My environment

  • Affects my production application: YES
  • Ruby version: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin24.2.0]
  • OS: macOS 15.2
@bkuhlmann bkuhlmann changed the title Fixed block being passed to __dry_initializer_initialize__ Fix block being passed to __dry_initializer_initialize__ Dec 28, 2024
@flash-gordon
Copy link
Member

Thanks for reporting, I saw it too and I'll take a closer look today. It's either justified or not. In the later case we'll have to silence this warning with a monkey patch I'm afraid. The problem is there's no way know if a method yields a block or not if doesn't appear in the parameters. And even if it does appear it would be more costly than just ignoring the warning.

@flash-gordon
Copy link
Member

Hmm, __dry_initializer_initialize__ doesn't yield a block so this warning seems justified. If we change the signature of Root#initialize to *, ** it'll help with referencing the correct source of the warning, I'll do this in main now.

flash-gordon added a commit that referenced this issue Dec 30, 2024
It will make ruby point to the correct source of the warning.

ref #109
@bkuhlmann
Copy link
Author

Thanks! Yeah, only forwarding positional and keyword parameters resolves this issue nicely. I also applied this patch locally and ran it across multiple projects and don't see any issues. My console is clean now. Would be nice to release a patch next if you don't see any further complications.

@flash-gordon
Copy link
Member

@bkuhlmann I pushed 3.2.0, please check it out

@bkuhlmann
Copy link
Author

Thanks, yep, looks good. 🙇 I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants