Commit f2a5f786
f2a5f786e830Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
block_given? for &block methods spelled with self
Recognize self.block_given? (not just the receiverless form) when marking a method block-aware, so it is inlined per call site and its block_given? reflects whether a block was passed. The codegen handler accepts a self receiver too.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- f2a5f786e830
- Parent
- 32265bc88e18
src/analyze.cmodifiedView file
@@ -2294,9 +2294,12 @@
22942294
const char *ty = nt_type(c->nt, id);22952295
if (!ty) continue;22962296
if (!strcmp(ty, "YieldNode")) comp_scope_of(c, id)->yields = 1;2297-
else if (!strcmp(ty, "CallNode") && nt_ref(c->nt, id, "receiver") < 0) {2297+
else if (!strcmp(ty, "CallNode")) {2298+
int r = nt_ref(c->nt, id, "receiver");2299+
const char *rty = r >= 0 ? nt_type(c->nt, r) : NULL;2300+
int self_or_none = r < 0 || (rty && !strcmp(rty, "SelfNode"));22982301
const char *nm = nt_str(c->nt, id, "name");2299-
if (nm && !strcmp(nm, "block_given?")) comp_scope_of(c, id)->yields = 1;2302+
if (self_or_none && nm && !strcmp(nm, "block_given?")) comp_scope_of(c, id)->yields = 1;23002303
}23012304
}23022305
src/codegen.cmodifiedView file
Loading diff…