mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: fix sp tracking in pattern match failure path
After pattern matching code generation, the sp (stack pointer) must be restored to match the success path value. The failure path (after RAISEIF) left sp in a different state, causing incorrect register allocation in subsequent code like string interpolation. This caused OP_STRCAT to use the wrong register, leading to null-dereference when trying to modify a non-string value as a string. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6667,6 +6667,9 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
|
||||
/* End of pattern matching */
|
||||
dispatch(s, match_pos);
|
||||
/* Restore sp to match success path value */
|
||||
s->sp = saved_sp - 1;
|
||||
if (val) push();
|
||||
}
|
||||
else {
|
||||
/* Pattern always matches - pop value and push result if needed */
|
||||
|
||||
Reference in New Issue
Block a user