summaryrefslogtreecommitdiff
path: root/prism_compile.c
diff options
context:
space:
mode:
authorLuke Gruber <[email protected]>2024-09-29 12:39:23 -0400
committerNobuyoshi Nakada <[email protected]>2024-10-01 02:12:56 +0900
commitd592ddd5e619ffe1691b8050de2ccc3e1bd6e080 (patch)
tree01102e6ea49ef52cf3c8ad4c5d1124d8ec088efc /prism_compile.c
parent2a58092360c70caf7544544c95549b4c83e81237 (diff)
Fix compile issue with a short-circuited if/unless condition and `defined?`
This caused an issue when `defined?` was in the `if` condition. Its instructions weren't appended to the instruction sequence even though it was compiled if a compile-time known logical short-circuit happened before the `defined?`. The catch table entry (`defined?` compilation produces a catch table entry) was still on the iseq even though the instructions weren't there. This caused faulty exception handling in the method. The solution is to no add the catch table entry for `defined?` after a compile-time known logical short circuit. This shouldn't touch much code, it's only for cases like the following, which can occur during debugging: if false && defined?(Some::CONSTANT) "more code..." end Fixes [Bug #20501]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11554
Diffstat (limited to 'prism_compile.c')
-rw-r--r--prism_compile.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 3e4de89f22..a9c8aea4b4 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -3310,7 +3310,7 @@ pm_scope_node_destroy(pm_scope_node_t *scope_node)
* Normally, "send" instruction is at the last. However, qcall under branch
* coverage measurement adds some instructions after the "send".
*
- * Note that "invokesuper" appears instead of "send".
+ * Note that "invokesuper", "invokesuperforward" appears instead of "send".
*/
static void
pm_compile_retry_end_label(rb_iseq_t *iseq, LINK_ANCHOR *const ret, LABEL *retry_end_l)
@@ -8154,9 +8154,10 @@ pm_compile_super_node(rb_iseq_t *iseq, const pm_super_node_t *node, const pm_nod
PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
}
- pm_compile_retry_end_label(iseq, ret, retry_end_l);
}
+ pm_compile_retry_end_label(iseq, ret, retry_end_l);
+
if (popped) PUSH_INSN(ret, *location, pop);
ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);