Commit 8f3f669f
8f3f669fa3faMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix 5 codegen/analyze bugs: poly dispatch, super-inline, fetch type
-
Unbox poly-typed array index in sp_XxxArray_get calls; when a method param is widened to sp_RbVal for poly dispatch, array subscript
@arr[i]passed lv_i directly to sp_IntArray_get which expects mrb_int (bundle_classd_28) -
Inline super { block } when parent method uses yield: add emit_super_inline that expands the parent body at the super call site with the passed block active, mirroring emit_inline_call_x (bundle_classd_48)
-
Fix poly dispatch arity padding + truncation: zero-arg dispatch now fills defaults for methods with nrequired==0 but nparams>0; multi-arg dispatch now accepts any method where argc>=nrequired, emitting defaults for missing optional params (bundle_classd_18)
-
Fix hash#fetch(key){block} when block return type differs from hash value type: detect mismatch, box both ternary arms to sp_RbVal; also fix infer_type to return TY_POLY for fetch+block when types differ so local variable declarations use the right C type (hash_fetch_block_key_type)
Refs #665, #655
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 8f3f669fa3fa
- Parent
- 820329620540
src/analyze.cmodifiedView file
if (recv >= 0 && ty_is_hash(rt)) { if (!strcmp(name, "[]")) return ty_hash_val(rt); if (!strcmp(name, "[]=")) return ty_hash_val(rt); if (!strcmp(name, "fetch")) return ty_hash_val(rt); if (!strcmp(name, "fetch")) { TyKind vt = ty_hash_val(rt); int blk = nt_ref(nt, id, "block"); if (blk >= 0) { int bbody = nt_ref(nt, blk, "body"); int bn = 0; const int *bb = bbody >= 0 ? nt_arr(nt, bbody, "body", &bn) : NULL; TyKind bvt = bn > 0 ? infer_type(c, bb[bn - 1]) : vt; if (bvt != vt) return TY_POLY; } return vt; } if (!strcmp(name, "delete")) return ty_hash_val(rt); if (!strcmp(name, "length") || !strcmp(name, "size") || !strcmp(name, "count")) return TY_INT;src/codegen.cmodifiedView file
Loading diff…