natalie icon indicating copy to clipboard operation
natalie copied to clipboard

defined? should not call const_missing

Open herwinw opened this issue 1 year ago • 0 comments

I ran into this issue when working on #1733.

The specs of https://github.com/ruby/spec/blob/master/language/optional_assignments_spec.rb have the following code (simplified):

class ClassA
  def self.const_missing(const)
    const
  end

  OR_ASSIGNED_CONSTANT1 ||= :assigned
end

p ClassA::OR_ASSIGNED_CONSTANT1

This prints :assigned in MRI, but ``:OR_ASSIGNED_CONSTANT1in Natalie. This code depends ondefined?`

p defined?(ClassA::NONE)

This prints nil in MRI, but "constant" in Natalie. defined? is not supposed to call const_missing.

herwinw avatar Jan 26 '24 20:01 herwinw