Skip to content

Commit 2036140

Browse files
committed
opt_new needs to happen after safe navigation
If safe navigation instructions happen first, we get a stack inconsistency error.
1 parent e6974be commit 2036140

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

prism_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,8 +3621,6 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
36213621

36223622
const pm_node_location_t location = PM_LOCATION_START_LOCATION(scope_node->parser, message_loc, call_node->base.node_id);
36233623

3624-
LINK_ELEMENT *opt_new_prelude = LAST_ELEMENT(ret);
3625-
36263624
LABEL *else_label = NEW_LABEL(location.line);
36273625
LABEL *end_label = NEW_LABEL(location.line);
36283626
LABEL *retry_end_l = NEW_LABEL(location.line);
@@ -3661,6 +3659,8 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
36613659
add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0, "then", branches);
36623660
}
36633661

3662+
LINK_ELEMENT *opt_new_prelude = LAST_ELEMENT(ret);
3663+
36643664
int flags = 0;
36653665
struct rb_callinfo_kwarg *kw_arg = NULL;
36663666

test/ruby/test_optimization.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,11 @@ def == x
12161216
RUBY
12171217
end
12181218

1219+
def test_opt_new_with_safe_navigation
1220+
payload = nil
1221+
assert_nil payload&.new
1222+
end
1223+
12191224
def test_opt_new
12201225
pos_initialize = "
12211226
def initialize a, b

0 commit comments

Comments
 (0)