Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Unhelpful error message when referencing missing constants in eigenclasses

#4923

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.

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

State: wontfix
Milestone: none
Assigned to: Xavier Noria Xavier Noria
Importance: Low

Activity

  1. José Valim
    José Valim

    Thanks for the patch mate, but could you please add, with the patch, a test reproducing this issue to ensure we won't have a regression?

    June 22nd, 2010 @ 04:48 PM

  2. José Valim
    José Valim
    • Assigned user set to Xavier Noria

    June 22nd, 2010 @ 04:53 PM

  3. Xavier Noria
    Xavier Noria
    • State changed from new to open
    • Importance changed from to Low

    I have had a look at this, it happens in 2.3 but not in master, so it has definitely low priority.

    Could have a look at it again if a complete patch with tests is provided.

    June 26th, 2010 @ 10:39 AM

  4. Xavier Noria
    Xavier Noria
    • State changed from open to wontfix

    Closing this by now to cleanup remaining tickets for RC. Please feel free to reopen with a patch.

    June 30th, 2010 @ 12:15 AM

  5. Rich Meyers
    Rich Meyers

    I was hoping that the solution could be implemented better. Catching ArgumentError like the patch I attached does is not something I want to see in rails.

    Is work on rails 2.3 stopped?

    August 17th, 2010 @ 09:46 PM

  6. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 11th, 2010 @ 10:58 AM

  7. Jeff Kreeftmeijer
  8. Jeff Kreeftmeijer