Commit 296472ce
296472ce2cf3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): expr-form raise handles 2-arg raise CLS, msg shape
Phase 1A of the exception handling gap fixes (project_exception_handling_gaps
memory). def helper; begin; raise StandardError, "inner"; rescue; raise; end; end previously failed C compile: the inner raise was the
body's only stmt and compile_body_return_inner's BeginNode arm routes
it via compile_body_into -> compile_expr -> the expr-form raise
arm at line ~15647, which emitted sp_raise(compile_expr(arg_ids[0]))
-- the first arg only. For 2-arg form that's the class (lowered to
sp_Class compound literal), and sp_raise expects const char *.
Mirror compile_control_call_stmt's 2-arg handling:
- arg_ids.length >= 2 + arg[0] is ConstantReadNode ->
sp_raise_cls( "ClassName", msg). - arg_ids.length == 1 + arg[0] is ConstantReadNode ->
sp_raise("ClassName"). - Otherwise pass msg through directly.
- arg_ids.empty / no args_id -> emit_bare_raise (existing behaviour).
Regression test: test/raise_reraise_in_def.rb covers re-raise + 2-arg
- 1-arg shapes inside def. Default tests 447/0/0, promote 446/0/0, optcarrot 59662 unchanged.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 296472ce2cf3
- Parent
- aa69596f090f
spinel_codegen.rbmodifiedView file
args_id = @nd_arguments[nid] if args_id >= 0 arg_ids = get_args(args_id) if arg_ids.length >= 1 emit(" sp_raise(" + compile_expr(arg_ids[0]) + ");") # `raise ClassName, "msg"` (2-arg form): emit sp_raise_cls with # the class name + message. Mirrors compile_control_call_stmt's # 2-arg arm. Pre-fix the expr-form emitted only the first arg # (the class), which sp_raise accepted as `(const char *)` and # blew up at C compile when the class lowered to an sp_Class # compound literal. Issue: bare-raise re-raise (#A in exception # handling gaps) surfaced this because compile_body_into routes # the body's last raise stmt through compile_expr. if arg_ids.length >= 2 if @nd_type[arg_ids[0]] == "ConstantReadNode" emit(" sp_raise_cls(\"" + @nd_name[arg_ids[0]] + "\", " + compile_expr(arg_ids[1]) + ");") else emit(" sp_raise(" + compile_expr(arg_ids[1]) + ");") end elsif arg_ids.length == 1 if @nd_type[arg_ids[0]] == "ConstantReadNode" emit(" sp_raise(\"" + @nd_name[arg_ids[0]] + "\");") else emit(" sp_raise(" + compile_expr(arg_ids[0]) + ");") end else emit_bare_raise end else emit_bare_raisetest/raise_reraise_in_def.rbaddedView file
Loading diff…