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

@@ -15649,8 +15649,28 @@
1564915649 args_id = @nd_arguments[nid]
1565015650 if args_id >= 0
1565115651 arg_ids = get_args(args_id)
15652- if arg_ids.length >= 1
15653- emit(" sp_raise(" + compile_expr(arg_ids[0]) + ");")
15652+ # `raise ClassName, "msg"` (2-arg form): emit sp_raise_cls with
15653+ # the class name + message. Mirrors compile_control_call_stmt's
15654+ # 2-arg arm. Pre-fix the expr-form emitted only the first arg
15655+ # (the class), which sp_raise accepted as `(const char *)` and
15656+ # blew up at C compile when the class lowered to an sp_Class
15657+ # compound literal. Issue: bare-raise re-raise (#A in exception
15658+ # handling gaps) surfaced this because compile_body_into routes
15659+ # the body's last raise stmt through compile_expr.
15660+ if arg_ids.length >= 2
15661+ if @nd_type[arg_ids[0]] == "ConstantReadNode"
15662+ emit(" sp_raise_cls(\"" + @nd_name[arg_ids[0]] + "\", " + compile_expr(arg_ids[1]) + ");")
15663+ else
15664+ emit(" sp_raise(" + compile_expr(arg_ids[1]) + ");")
15665+ end
15666+ elsif arg_ids.length == 1
15667+ if @nd_type[arg_ids[0]] == "ConstantReadNode"
15668+ emit(" sp_raise(\"" + @nd_name[arg_ids[0]] + "\");")
15669+ else
15670+ emit(" sp_raise(" + compile_expr(arg_ids[0]) + ");")
15671+ end
15672+ else
15673+ emit_bare_raise
1565415674 end
1565515675 else
1565615676 emit_bare_raise