Commit d74c83f8
d74c83f8ff38Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Extend yield: instance methods + mixed-arity zero-padding
- emit_inline_call handles instance-method yield:
obj.m { }binds self to the receiver (a sp_* temp; g_self override threads it through ivar access, implicit-self dispatch, and super); implicit-self yield calls (recv<0 resolving to an enclosing-class method) inline against the current self. infer_block_params binds block params from instance/ implicit-self yield args too. - YieldNode now zeroes block params beyond the yield's arity, so a smaller yield in a mixed-arity method doesn't leak a previous yield's values (fixes multi_arg_yield).
A class with a yielding iterator called externally and via implicit self
(with a captured accumulator), and mixed-arity yields, match CRuby.
make test: 26.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- d74c83f8ff38
- Parent
- 9e9aa474ec40
src/analyze.cmodifiedView file
@@ -893,11 +893,17 @@
893893
if (!name) continue;894894
895895
/* call to a user yielding method: block params take the yield arg types */896-
if (recv < 0) {897-
int mi = comp_method_index(c, name);898-
if (mi < 0) {899-
Scope *self = comp_scope_of(c, id);900-
if (self->class_id >= 0) mi = comp_method_in_chain(c, self->class_id, name, NULL);896+
{897+
int mi = -1;898+
if (recv < 0) {899+
mi = comp_method_index(c, name);900+
if (mi < 0) {901+
Scope *self = comp_scope_of(c, id);902+
if (self->class_id >= 0) mi = comp_method_in_chain(c, self->class_id, name, NULL);903+
}904+
} else {905+
TyKind rt0 = infer_type(c, recv);906+
if (ty_is_object(rt0)) mi = comp_method_in_chain(c, ty_object_class(rt0), name, NULL);901907
}902908
if (mi >= 0 && c->scopes[mi].yields) {903909
int yn = first_yield(c, mi);src/codegen.cmodifiedView file
Loading diff…