-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Refinements do not refine #4330
Comments
Isn't this the same as #3548? |
Yep, looks alike, yet that one marked as closed. And mine is still actual. |
The issue is still on v9.1.8.0 |
It seems like JRuby doesn't correctly implement refinements see (jruby/jruby#4330) so the only way around this was to revert to monkey-patching the base classes. New file lib/ruby/jruby_hack.rb is copy-pasted code from each lib/ruby file, except instead of 'refine X do { ... }' it's changed to 'class X { ... }'. There was also an incompatibility with Nn.to_d - Nn, which fails with "Nn cannot be coerced to BigDecimal"; this might be an error in the BigDecimal class on JRuby? For now, those specs are marked pending on JRuby. Redcarpet is a C-extension for MRI, so I disabled it for JRuby, but documentation can be accessed online (just not built on JRuby)
Can this fact at least be mentioned and explained in Wiki? https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby I know there are different views on refinements, but it is a major language feature that is just silently ignored by JRuby for literally years now. |
I understand this has been frustrating. I'm going to pin this to my todo list and try to get refinements working better for 9.2, which we hope to release in about a month. The wiki is publicly editable...please feel free to add refinements as a topic on that page. |
This does indeed appear to be fixed in 9.2.0.0 (I came across it when trying to use the Origami gem). |
Hey, that's one issue down! Thanks for verifying. |
I believe I've checked that with 9.2.0.0. It was working on different classes, but not with |
Sorry :(
test.rb: p RUBY_DESCRIPTION
module Refinements
refine Object do
def derp
yield self
end
end
end
module A
using Refinements
def self.foo
'test'.derp { |s| '(' + s + ')' }
end
end
p A.foo # => "(test)" With my regular Ruby:
Probaby the problem now is much more local than "refinements do not work at all". |
I too have a breaking case in 9.2.0.0. It isn't quite the same as zverok's.
jruby:
ruby:
|
It looks like i18n 1.3.0 is not usable on jruby 9.1 and 9.2 due to refinements. i18n has this code: module I18n module HashRefinements refine Hash do def slice(*keep_keys) h = {} keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) } h end def except(*less_keys) slice(*keys - less_keys) end def deep_symbolize_keys each_with_object({}) do |(key, value), result| value = value.deep_symbolize_keys if value.is_a?(Hash) result[symbolize_key(key)] = value result end end # deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809 def deep_merge!(data) merger = lambda do |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 end merge!(data, &merger) end private def symbolize_key(key) key.respond_to?(:to_sym) ? key.to_sym : key end end end end And this produces the following error in Mongoid test suite: 1) Mongoid::Criteria#asc when the documents are embedded returns the sorted documents Failure/Error: field :_id, type: String, overwrite: true, default: ->{ street.try(:parameterize) } NoMethodError: undefined method `symbolize_key' for # # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/core_ext/hash.rb:17:in `block in deep_symbolize_keys' # org/jruby/RubyHash.java:1396:in `each' # org/jruby/RubyEnumerable.java:1190:in `each_with_object' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/core_ext/hash.rb:15:in `deep_symbolize_keys' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/simple.rb:46:in `store_translations' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/base.rb:220:in `block in load_file' # org/jruby/RubyHash.java:1396:in `each' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/base.rb:220:in `load_file' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/base.rb:18:in `block in load_translations' # org/jruby/RubyArray.java:1801:in `each' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/base.rb:18:in `load_translations' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/simple.rb:77:in `init_translations' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/simple.rb:87:in `lookup' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/base.rb:32:in `translate' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n.rb:185:in `block in translate' # org/jruby/RubyKernel.java:1180:in `catch' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n.rb:181:in `translate' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n/backend/transliterator.rb:13:in `transliterate' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/i18n-1.3.0/lib/i18n.rb:263:in `transliterate' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-5.2.2/lib/active_support/inflector/transliterate.rb:64:in `transliterate' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-5.2.2/lib/active_support/inflector/transliterate.rb:94:in `parameterize' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-5.2.2/lib/active_support/core_ext/string/inflections.rb:191:in `parameterize' # org/jruby/RubyKernel.java:1942:in `public_send' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-5.2.2/lib/active_support/core_ext/object/try.rb:19:in `try!' # /home/w/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-5.2.2/lib/active_support/core_ext/object/try.rb:8:in `try' # ./spec/app/models/address.rb:6:in `block in ___id_default__' # ./lib/mongoid/fields/standard.rb:241:in `evaluate_default_proc' # ./lib/mongoid/fields/standard.rb:223:in `evaluated_default' # ./lib/mongoid/fields/standard.rb:45:in `eval_default' # ./lib/mongoid/fields.rb:104:in `apply_default' # ./lib/mongoid/fields.rb:89:in `block in apply_post_processed_defaults' # org/jruby/RubyArray.java:1801:in `each' # ./lib/mongoid/fields.rb:88:in `apply_post_processed_defaults' ... |
@p-mongo yeah we noticed that last week when we thought we were going to put out 9.2.6.0 (same day they released with the refinements version of i18n). So 9.2.6.0 will for sure get a fix for this, but we are on xmas break until new year. Expect greenness at beginning of January. |
I tried the evil seed gem and we're running Rails 4.2.11 and Jruby 9.2.5.0, and I noticed it's using refinements to back port Rails I opened an issue here: I believe based on this thread, that refinements are not supported correctly on this version of JRuby. Is that correct? |
@andyatkinson Can you check whatever bug you're interested in again once we land #5627 (ideally tomorrow or Wednesday) and see if you still have issues? I suspect this will be fixed, or at least improved, by #5604 and #5627. |
Oh and if there's still issues...can I humbly request you submit a new issue with a new example script, so we can keep the different issues straight? |
Environment
Expected Behavior
Works in any MRI Ruby 2.1+
Actual Behavior
Note
I believe, as this example is VERY basic and nobody have complained about the behavior, the refinements are really not used in community... Or JRuby users are used to not rely on them, at least. So, it is hard to estimate how severe the bug should be considered.
The text was updated successfully, but these errors were encountered: