Commit 8505715f
8505715f8e0fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Poly method dispatch with arguments
When a call's receiver is poly, the target user method is not statically known, so its params were never bound and stayed unknown, failing to compile ("param has unsupported type unknown").
Inference: for a poly receiver, bind the params of every user method matching the call name, so candidate methods get typed from the arg types.
Codegen: extend the poly cls_id switch to argument-bearing calls. Evaluate
the receiver and args once into temps, then dispatch to the matching user
method per class (and to sp_IntArray_get for a builtin-array []).
Enables a.call(x) / a[i] where a may be one of several classes.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 8505715f8e0f
- Parent
- 9f59e4bd4906
src/analyze.cmodifiedView file
TyKind rt = infer_type(c, recv); if (ty_is_object(rt)) changed |= bind_call_params(c, id, comp_method_in_chain(c, ty_object_class(rt), name, NULL)); else if (rt == TY_POLY) { /* poly receiver: the call may dispatch to any user method of this name, so bind every candidate's params (they would otherwise stay UNKNOWN and fail to compile). */ for (int k = 0; k < c->nclasses; k++) changed |= bind_call_params(c, id, comp_method_in_chain(c, k, name, NULL)); } } return changed;}src/codegen.cmodifiedView file
Loading diff…