dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Warning about pattern matching on Ruby 2.7 #441

Closed r7kamura closed 1 year ago

r7kamura commented 1 year ago

Describe the bug

As stated in the gemspec, this gem should support Ruby 2.7 or higher.

spec.required_ruby_version = ">= 2.7.0"

Even so, pattern matching is used in the code, which should not have been formally introduced in Ruby 2.7, and which is still in the experimental phase.

As a result, various codes that use this gem (e.g., Rails apps with config gem) are now generating the following warning when run under Ruby 2.7.

$ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
$ bin/rails c
/usr/local/bundle/gems/dry-schema-1.10.6/lib/dry/schema/types_merger.rb:71: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
Loading development environment (Rails 7.0.3.1)
irb(main):001:0> 

This pattern matching code was added in the following Pull Request and appears to have been introduced in v1.10.0.

To Reproduce

The easiest way to reproduce this is to require 'dry/schema/types_merger' on Ruby 2.7.

$ ruby -v
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux]
$ bundle exec ruby -I lib -e "require 'dry/schema/types_merger'"
/home/r7kamura/ghq/github.com/dry-rb/dry-schema/lib/dry/schema/types_merger.rb:71: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!

Expected behavior

If Ruby 2.7 is supported, at least the implementation in the lib directory should not use pattern matching so that no warnings are generated at runtime. And if we use pattern matching, we should drop support for Ruby 2.7.

My environment