[前][次][番号順一覧][スレッド一覧]

ruby-changes:56121

From: Yuki <ko1@a...>
Date: Sun, 16 Jun 2019 22:48:25 +0900 (JST)
Subject: [ruby-changes:56121] Yuki Yugui Sonoda: 44caca11cf (trunk): Make constant assignments more conforming to JIS X 3017:2013 11.4.2.2.3

https://git.ruby-lang.org/ruby.git/commit/?id=44caca11cf

From 44caca11cfa6bea01a1ef738846183f1a56d5658 Mon Sep 17 00:00:00 2001
From: Yuki Yugui Sonoda <yugui@y...>
Date: Sun, 16 Jun 2019 22:28:34 +0900
Subject: Make constant assignments more conforming to JIS X 3017:2013
 11.4.2.2.3

compile.c (NODE_CDECL): Evaluate the module before the value
test/ruby/test_const.rb (test_evaluation_order): added a test case

diff --git a/compile.c b/compile.c
index 80dc5e7..6351914 100644
--- a/compile.c
+++ b/compile.c
@@ -6855,21 +6855,26 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in https://github.com/ruby/ruby/blob/trunk/compile.c#L6855
 	break;
       }
       case NODE_CDECL:{
-	CHECK(COMPILE(ret, "lvalue", node->nd_value));
-
-	if (!popped) {
-	    ADD_INSN(ret, line, dup);
-	}
-
+        ID base_id;
 	if (node->nd_vid) {
 	    ADD_INSN1(ret, line, putspecialobject,
 		      INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
-	    ADD_INSN1(ret, line, setconstant, ID2SYM(node->nd_vid));
+	    base_id = node->nd_vid;
 	}
 	else {
 	    compile_cpath(ret, iseq, node->nd_else);
-	    ADD_INSN1(ret, line, setconstant, ID2SYM(node->nd_else->nd_mid));
+	    base_id = node->nd_else->nd_mid;
 	}
+	CHECK(COMPILE(ret, "lvalue", node->nd_value));
+
+	if (popped) {
+            ADD_INSN(ret, line, swap);
+	} else {
+	    ADD_INSN(ret, line, dup);
+            ADD_INSN1(ret, line, reverse, INT2FIX(3));
+	}
+
+	ADD_INSN1(ret, line, setconstant, ID2SYM(base_id));
 	break;
       }
       case NODE_CVASGN:{
diff --git a/test/ruby/test_const.rb b/test/ruby/test_const.rb
index 8784e0e..fa512aa 100644
--- a/test/ruby/test_const.rb
+++ b/test/ruby/test_const.rb
@@ -69,4 +69,12 @@ PRE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_const.rb#L69
   def test_toplevel_lookup
     assert_raise(NameError, '[Feature #11547]') {TestConst::Object}
   end
+
+  def test_evaluation_order
+    assert_raise_with_message(RuntimeError, "recv", 'JIS X 3017:2013 11.4.2.2.3') {
+      eval <<~EOS
+        raise('recv')::C = raise('value')
+      EOS
+    }
+  end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]