mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler/codegen.c: stop too aggressive optimization; fix #6210
The old code assumes unary minus (`-@`) does not cause any side effect (including errors). Considering the code like `-nil; nil`, the assumption was too aggressive.
This commit is contained in:
@@ -3366,19 +3366,14 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val) {
|
||||
codegen(s, tree, VAL);
|
||||
pop();
|
||||
push_n(2);pop_n(2); /* space for receiver&block */
|
||||
mrb_sym minus = MRB_OPSYM_2(s->mrb, minus);
|
||||
if (!gen_uniop(s, minus, cursp())) {
|
||||
genop_3(s, OP_SEND, cursp(), new_sym(s, minus), 0);
|
||||
}
|
||||
push();
|
||||
}
|
||||
else {
|
||||
codegen(s, tree, NOVAL);
|
||||
codegen(s, tree, VAL);
|
||||
pop();
|
||||
push_n(2);pop_n(2); /* space for receiver&block */
|
||||
mrb_sym minus = MRB_OPSYM_2(s->mrb, minus);
|
||||
if (!gen_uniop(s, minus, cursp())) {
|
||||
genop_3(s, OP_SEND, cursp(), new_sym(s, minus), 0);
|
||||
}
|
||||
if (val) push();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user