Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #146 by not reassigning self to Builtin
we need a way to denote classes that just contain macros, so we can ensure this is done across the board. This just fixes it for Builtins. Perhaps we should add an annotation for macros?
  • Loading branch information
baroquebobcat committed Sep 25, 2011
1 parent 8fb471e commit 31074c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mirah/jvm/types/intrinsics.rb
Expand Up @@ -92,10 +92,15 @@ def add_compiled_macro(klass, name, arg_types)
if ast
body = Mirah::AST::ScopedBody.new(call.parent, call.position)
body << ast
if call.target

# if the macro was called on something, and that something
# was not a class only containing macros, reassign self for
# the body.
if call.target && !call.target.is_a?(Mirah::AST::Builtin)
body.static_scope.self_type = call.target.inferred_type!
body.static_scope.self_node = call.target
end

body
else
Mirah::AST::Noop.new(call.parent, call.position)
Expand Down
27 changes: 27 additions & 0 deletions test/jvm/test_jvm_compiler.rb
Expand Up @@ -2159,6 +2159,33 @@ def set(b:Object)
assert_equal("foo", cls.set("foo"))
end

def test_hash_with_value_from_static_method
cls, = compile(<<-EOF)
def foo1
{a: a, b:"B"}
end
def a
return "A"
end
EOF
assert_equal("A", cls.foo1["a"])
end

def test_hash_with_value_from_instance_method
cls, = compile(<<-EOF)
class HashTesty
def foo1
{a: a, b:"B"}
end
def a
return "A"
end
end
EOF
assert_equal("A", cls.new.foo1["a"])
end


def test_loop_in_ensure
cls, = compile(<<-EOF)
begin
Expand Down

0 comments on commit 31074c6

Please sign in to comment.