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

NameError different behavior #2869

Closed
gazay opened this Issue Apr 23, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@gazay
Copy link
Contributor

gazay commented Apr 23, 2015

bug from rails tests

def catch_error
  Class.const_get '::'
rescue => e
  puts "name: #{e.name}"
  raise e
end

catch_error

MRI output:

name: ::
NameError: wrong constant name ::
    from (irb):2:in `const_get'
    from (irb):2:in `catch_error'
    from (irb):8
    from /Users/alex/.rubies/ruby-2.2.2/bin/irb:11:in `<main>'

Jruby output:

name:
NameError: wrong constant name ::
    from org/jruby/RubyModule.java:3054:in `const_get'
    from (irb):15:in `catch_error'
    from (irb):21:in `<eval>'
    from org/jruby/RubyKernel.java:1005:in `eval'
    from org/jruby/RubyKernel.java:1315:in `loop'
    from org/jruby/RubyKernel.java:1125:in `catch'
    from org/jruby/RubyKernel.java:1125:in `catch'
    from /Users/alex/.rubies/jruby-9.0.0.0-SNAPSHOT/bin/irb:13:in `<top>'

Failing test in AS:
https://github.com/rails/rails/blob/master/activesupport/test/constantize_test_cases.rb#L90
https://github.com/rails/rails/blob/master/activesupport/test/core_ext/string_ext_test.rb#L296

NameError#name should return :: as provided constant name but it returns empty string

Backtrace:

StringInflectionsTest#test_safe_constantize:
NameError: wrong constant name ::
    org/jruby/RubyModule.java:3054:in `const_get'
    rails/activesupport/lib/active_support/inflector/methods.rb:254:in `constantize'
    rails/activesupport/lib/active_support/inflector/methods.rb:304:in `safe_constantize'
    rails/activesupport/lib/active_support/core_ext/string/inflections.rb:77:in `safe_constantize'
    rails/activesupport/test/constantize_test_cases.rb:90:in `run_safe_constantize_tests_on'
    rails/activesupport/test/core_ext/string_ext_test.rb:296:in `test_safe_constantize'

Re-run test from activesupport directory with: ruby -w -Itest test/core_ext/string_ext_test.rb -n test_safe_constantize

@gazay

This comment has been minimized.

Copy link
Contributor Author

gazay commented Apr 23, 2015

There is more difference:

def catch_err
  Class.const_get 'Some'
rescue => e
  e.name
end

MRI

=> "Some"

Jruby

=> :"Class::Some"
@headius

This comment has been minimized.

Copy link
Member

headius commented Apr 29, 2015

Very weird thing for Rails to be testing, but I think I have a fix.

@headius headius closed this in e937702 Apr 29, 2015

@headius

This comment has been minimized.

Copy link
Member

headius commented Apr 29, 2015

@gazay Thanks for the good case! I believe JRuby matches all the examples you provided. Perhaps you'd like to take another step and add specs for some of these cases to https://github.com/ruby/rubyspec under core/module/const_get_spec.rb and friends? It's fun, and would let us move on to the next bug fix :-)

@headius headius added this to the JRuby 9.0.0.0.rc1 milestone Apr 29, 2015

@gazay

This comment has been minimized.

Copy link
Contributor Author

gazay commented Apr 29, 2015

Sure, thanks for idea =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.