Skip to content
Permalink
Browse files

Merge pull request #747 from gemoe100/fix_defined

Fix defined
  • Loading branch information
alex committed Jun 3, 2013
2 parents 054f9b1 + 0fcaddb commit ee871cc0c556b914d53b9f8ee8885d3baea9622d
Showing with 25 additions and 2 deletions.
  1. +22 −0 tests/objects/test_moduleobject.py
  2. +2 −1 topaz/interpreter.py
  3. +1 −1 topaz/objects/moduleobject.py
@@ -400,6 +400,28 @@ def test_anon_class_name(self, space):
w_res = space.execute("return Module.new.name")
assert w_res is space.w_nil

def test_definedp(self, space):
w_res = space.execute("""
module A
def self.foo_defined?
defined?(@foo)
end
end
return A.foo_defined? ? 'yes' : 'no'
""")
assert self.unwrap(space, w_res) == 'no'
w_res = space.execute("""
module A
@foo = nil
def foo_defined?
defined?(@foo)
end
end
return A.foo_defined? ? 'yes' : 'no'
""")
assert self.unwrap(space, w_res) == 'yes'


class TestMethodVisibility(object):
def test_private(self, space):
@@ -235,7 +235,8 @@ def DEFINED_LOCAL_CONSTANT(self, space, bytecode, frame, pc, idx):
def LOAD_INSTANCE_VAR(self, space, bytecode, frame, pc, idx):
w_name = bytecode.consts_w[idx]
w_obj = frame.pop()
w_res = space.find_instance_var(w_obj, space.symbol_w(w_name))
w_res = (space.find_instance_var(w_obj, space.symbol_w(w_name))
or space.w_nil)
frame.push(w_res)

def STORE_INSTANCE_VAR(self, space, bytecode, frame, pc, idx):
@@ -261,7 +261,7 @@ def set_instance_var(self, space, name, w_value):
return self.instance_variables.set(space, name, w_value)

def find_instance_var(self, space, name):
return self.instance_variables.get(space, name) or space.w_nil
return self.instance_variables.get(space, name)

def copy_instance_vars(self, space, w_other):
assert isinstance(w_other, W_ModuleObject)

0 comments on commit ee871cc

Please sign in to comment.