This project is archived and is in readonly mode.

#4923 ✓wontfix
Rich Meyers

Unhelpful error message when referencing missing constants in eigenclasses

Reported by Rich Meyers | June 21st, 2010 @ 06:08 PM

Referencing undefined/missing constants when in eigenclasses results in an error message that does not mention true problem (undefined/missing constant) nor which constant was referenced, as in the following code:

require 'config/boot'
require 'config/environment'

class Base
  class << self
    def foo
      # ArgumentError: Anonymous modules have no name to be referenced by
      # vendor/rails/activesupport/lib/active_support/dependencies.rb:585:in `to_constant_name'
      # vendor/rails/activesupport/lib/active_support/dependencies.rb:391:in `qualified_name_for'
      # vendor/rails/activesupport/lib/active_support/dependencies.rb:104:in `const_missing'
      # rails 2.3.8
      Missing
    end
  end
end

class Sub < Base
  # Can call foo directly from base, but this is the usual use case
  foo
end

One of const_missing, qualified_name_for or to_constant_name ought to account for the current class being an eigenclass and raise an exception with a sensible message.

Attached patch fixes the issue, although the fix could likely be improved.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages