Commit 8916bb9c

8916bb9cdbaaMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Fix String << poly-typed arg and ParenthesesNode chain walk

When a TY_POLY value is appended to a String with <<, wrap the arg in sp_poly_to_s() so sp_str_concat() receives const char* as required.

Also fix the << chain walk to unwrap ParenthesesNode wrappers: Prism wraps (s << a) << b with a ParenthesesNode/StatementsNode pair around the inner <<, causing the chain walk to terminate early and fall through to unsupported emit_call.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
8916bb9cdbaa
Parent
47f4dbb41704

src/codegen.cmodifiedView file

@@ -6008,6 +6008,14 @@
60086008 int chain[64]; int nchain = 0;
60096009 int cur = id;
60106010 while (nchain < 64) {
6011+ /* unwrap ParenthesesNode wrappers (e.g. `(s << a) << b`) */
6012+ while (nt_type(nt, cur) && !strcmp(nt_type(nt, cur), "ParenthesesNode")) {
6013+ int pb = nt_ref(nt, cur, "body");
6014+ if (pb < 0) break;
6015+ int bn = 0; const int *bb = nt_arr(nt, pb, "body", &bn);
6016+ if (bn != 1) break;
6017+ cur = bb[0];
6018+ }
60116019 const char *cty = nt_type(nt, cur);
60126020 if (!cty || strcmp(cty, "CallNode")) break;
60136021 const char *cnm = nt_str(nt, cur, "name");
@@ -6030,6 +6038,7 @@
60306038 emit_expr(c, cur, b); buf_puts(b, " = sp_str_concat(");
60316039 emit_expr(c, cur, b); buf_puts(b, ", ");
60326040 if (at == TY_INT) { buf_puts(b, "sp_int_codepoint_to_str("); emit_expr(c, arg, b); buf_puts(b, ")"); }
6041+ else if (at == TY_POLY) { buf_puts(b, "sp_poly_to_s("); emit_expr(c, arg, b); buf_puts(b, ")"); }
60336042 else emit_expr(c, arg, b);
60346043 buf_puts(b, ");\n");
60356044 }