Commit d43bdc75
d43bdc756ba3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix module constant array type inference and initialization codegen
analyze.c: extend infer_global_const_types to detect CONST << v / CONST.push(v) / CONST.append(v) patterns and infer the constant's array type from the pushed element type, so LOG = [] followed by LOG << hash_entry produces sp_PolyArray instead of the default sp_IntArray.
codegen.c: fix ConstantWriteNode / GlobalVariableWriteNode empty array/hash initialization to use the type-appropriate constructor (sp_PolyArray_new, sp_StrArray_new, sp_IntIntHash_new, etc.) when the constant's inferred type is already known, mirroring the existing ivar write logic.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- d43bdc756ba3
- Parent
- 39d081dc7046
src/analyze.cmodifiedView file
} continue; } else if (!strcmp(ty, "CallNode")) { /* CONST << v / CONST.push(v) / CONST.append(v): infer CONST as an array whose element type comes from v's type. Only applies when the receiver is a direct ConstantReadNode. */ const char *cnm = nt_str(nt, id, "name"); if (!cnm) continue; int is_push = (!strcmp(cnm, "<<") || !strcmp(cnm, "push") || !strcmp(cnm, "append")); if (!is_push) continue; int crecv = nt_ref(nt, id, "receiver"); if (crecv < 0) continue; const char *rty = nt_type(nt, crecv); if (!rty || strcmp(rty, "ConstantReadNode")) continue; const char *cnm2 = nt_str(nt, crecv, "name"); if (!cnm2) continue; lv = comp_const(c, cnm2); if (!lv || lv->type != TY_UNKNOWN) continue; int cargs = nt_ref(nt, id, "arguments"); int cac = 0; const int *cav = cargs >= 0 ? nt_arr(nt, cargs, "arguments", &cac) : NULL; if (cac < 1 || !cav) continue; TyKind et = infer_type(c, cav[0]); if (et == TY_UNKNOWN || et == TY_NIL) continue; vt = ty_array_of(et); if (vt == TY_UNKNOWN) vt = TY_POLY_ARRAY; } else { continue; }src/codegen.cmodifiedView file
Loading diff…