Skip to content
Browse files

Constant set fixed

  • Loading branch information...
1 parent 75e34c8 commit 4c2754636e59ad6eee3140b036e134e0f00ecef1 @txus committed Jan 27, 2012
Showing with 15 additions and 3 deletions.
  1. +10 −3 lib/noscript/compiler.rb
  2. +5 −0 test/interop_test.rb
View
13 lib/noscript/compiler.rb
@@ -221,9 +221,16 @@ def visit_SlotGet(o)
def visit_SlotAssign(o)
set_line(o)
o.receiver.accept(self)
- g.push_literal o.name
- o.value.accept(self)
- g.send :__noscript_put__, 2
+
+ if o.receiver.constant? && AST::Identifier.new(1, o.name).constant? # Constant set like Rubinius.Compiler = something
+ g.push_literal o.name.to_sym
+ o.value.accept(self)
+ g.send :const_set, 2
+ else
+ g.push_literal o.name
+ o.value.accept(self)
+ g.send :__noscript_put__, 2
+ end
end
def visit_IfNode(o)
View
5 test/interop_test.rb
@@ -17,6 +17,11 @@ def test_toplevel_namespace
assert_equal Fixnum, compile("Ruby.Fixnum")
end
+ def test_assign_toplevel_namespace
+ compile("Ruby.Answer = 42")
+ assert_equal 42, ::Answer
+ end
+
def test_define_ruby_method
compile(<<-CODE)
Ruby.Array.def('sum', ->

0 comments on commit 4c27546

Please sign in to comment.
Something went wrong with that request. Please try again.