summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorYuki Yugui Sonoda <yugui@yugui.jp>2019-06-16 22:28:34 +0900
committerYuki Yugui Sonoda <yugui@yugui.jp>2019-06-16 22:43:03 +0900
commit44caca11cfa6bea01a1ef738846183f1a56d5658 (patch)
tree65538995ed3d9e6ef425b0c11c604bca1eebe991 /compile.c
parent2fb1564c02899c73519164ddf3f2430dfbc8f3d6 (diff)
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
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/compile.c b/compile.c
index 80dc5e729a..6351914f7f 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
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:{