Commit 8482dd6d

8482dd6d304bMerged

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

Description

JSON.generate / JSON.dump for scalars, arrays, and hashes

JSON.generate(x)/dump(x) serialize a boxed value via the runtime sp_json_val. emit_boxed now boxes the str_poly / sym_poly hash variants too (via the shared hash_box_cls map), so a hash with mixed values serializes. User objects (no serializer yet) are left to fall through.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
8482dd6d304b
Parent
7b48ef1500a5

src/analyze.cmodifiedView file

@@ -316,6 +316,10 @@
316316 !strcmp(name, "sqrt"))
317317 return TY_INT;
318318 if (rty && !strcmp(rty, "ConstantReadNode") &&
319+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "JSON") &&
320+ (!strcmp(name, "generate") || !strcmp(name, "dump")))
321+ return TY_STRING;
322+ if (rty && !strcmp(rty, "ConstantReadNode") &&
319323 nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "Dir") &&
320324 (!strcmp(name, "exist?") || !strcmp(name, "exists?")))
321325 return TY_BOOL;