Skip to content

NameError different behavior #2869

@gazay

Description

@gazay

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions