Commit 52462db9
52462db9be55Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Fix Time.new(args) dispatch and stdlib .new fallback brace scope
Time.new(year,...) was falling through to the unknown-class 0LL fallback in the Class.new dispatch section, because the dedicated Time constructor handler at the later section was never reached. Add a Time case in the Class.new section that forwards to sp_time_new/sp_time_now.
Also fix the unknown-class fallback placement: it was inside the
Array.new(n,v) if(k) block instead of after it, so Pathname/OpenStruct
etc. .new calls also fell through to unsupported-call instead of emitting
the no-op 0LL sentinel.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 52462db9be55
- Parent
- ee5107cff216
src/codegen.cmodifiedView file
@@ -5398,6 +5398,19 @@
53985398
return;53995399
}54005400
}5401+
if (cn && !strcmp(cn, "Time")) {5402+
if (argc == 0) { buf_puts(b, "sp_time_now()"); return; }5403+
buf_printf(b, "sp_time_new(");5404+
for (int i = 0; i < 6; i++) {5405+
if (i) buf_puts(b, ", ");5406+
if (i < argc) emit_expr(c, argv[i], b);5407+
else buf_puts(b, (i == 1 || i == 2) ? "1" : "0");5408+
}5409+
buf_puts(b, ")");5410+
return;5411+
}5412+
/* unrecognized stdlib class .new (Pathname, OpenStruct, IPAddr, etc.): emit 0 */5413+
if (cn) { buf_puts(b, "0LL"); return; }54015414
}54025415
}54035416
@@ -16422,7 +16435,10 @@
1642216435
}1642316436
default: break;1642416437
}16425-
if (!fn) { unsupported(c, node, "boxing value into poly"); return; }16438+
if (!fn) {16439+
/* TY_UNKNOWN (e.g. unrecognized stdlib class .new): evaluate for side-effects, yield nil */16440+
buf_puts(b, "("); emit_expr(c, node, b); buf_puts(b, ", sp_box_nil())"); return;16441+
}1642616442
buf_printf(b, "%s(", fn);1642716443
emit_expr(c, node, b);1642816444
buf_puts(b, ")");