Permalink
Browse files

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...
1 parent 8fb471e commit 31074c6861f3c5b7c2529f262e90ca1d460cbc53 @baroquebobcat baroquebobcat committed Sep 25, 2011
Showing with 33 additions and 1 deletion.
  1. +6 −1 lib/mirah/jvm/types/intrinsics.rb
  2. +27 −0 test/jvm/test_jvm_compiler.rb
@@ -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)
@@ -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

0 comments on commit 31074c6

Please sign in to comment.