Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 31074c6861f3c5b7c2529f262e90ca1d460cbc53 1 parent 8fb471e
@baroquebobcat baroquebobcat authored
View
7 lib/mirah/jvm/types/intrinsics.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)
View
27 test/jvm/test_jvm_compiler.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.