Commit bdb61ab3

bdb61ab35b01Merged

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

Description

Support IndexOrWriteNode/IndexAndWriteNode and TY_POLY << dispatch

Type inference: IndexOrWriteNode/IndexAndWriteNode return the element type for typed arrays/hashes, and TY_POLY as a fallback for general receivers.

Code generation:

  • IndexOrWriteNode/IndexAndWriteNode in emit_expr: handle TY_POLY_ARRAY, TY_INT_ARRAY, TY_STR_ARRAY, typed hash receivers, and TY_POLY (via sp_poly_get_str/sp_poly_set_str for string keys).
  • TY_POLY << in both value and statement positions via sp_poly_shl.

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

Details

Commit
bdb61ab35b01
Parent
464810f651dc

src/analyze.cmodifiedView file

@@ -1324,6 +1324,14 @@
13241324 !strcmp(ty, "ClassVariableOrWriteNode") ||
13251325 !strcmp(ty, "ClassVariableAndWriteNode"))
13261326 return infer_type(c, nt_ref(nt, id, "value"));
1327+ if (!strcmp(ty, "IndexOrWriteNode") || !strcmp(ty, "IndexAndWriteNode")) {
1328+ int recv = nt_ref(nt, id, "receiver");
1329+ if (recv < 0) return TY_UNKNOWN;
1330+ TyKind rt = infer_type(c, recv);
1331+ if (ty_is_array(rt)) return ty_array_elem(rt);
1332+ if (ty_is_hash(rt)) return ty_hash_val(rt);
1333+ return TY_POLY;
1334+ }
13271335 if (!strcmp(ty, "ParenthesesNode")) {
13281336 int body = nt_ref(nt, id, "body");
13291337 if (body < 0) return TY_NIL;