Project

General

Profile

Actions

Bug #12109

closed

Exception during class load can cause partially-loaded class

Added by arrtchiu (Matt U) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
[ruby-core:73971]

Description

I noticed this bug using Rails, which lazy-loads classes (via ActiveSupport.)

Here's a minimal test case:

#!/usr/bin/env ruby

begin
  # simulate loading a class from file at runtime
  eval %q{
    class Foo
      def self.bar
        fail 'bar'
      end

      bar

      def self.baz
        puts 'baz'
      end
    end
  }
rescue => e
  puts "rescued: #{e}"
end
# => rescued: bar

Foo.baz
# => undefined method `baz' for Foo:Class (NoMethodError)

EXPECTED
Either:

  • No exception - finish adding the method to the class, or
  • 'undefine' the class, at least making it obvious that the class didn't load completely (or in the case of rails/activesupport, allow it to be reloaded on-demand later)
Actions

Also available in: Atom PDF

Like0
Like0Like0