Commit 7a3a0611
7a3a0611a278Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #1424 from OriPekelman/fix/bare-module-body-cmethod-ret-type
analyze: type a bare module/class-body cmethod call via node_cbody (fixes the void-arg drop behind tep#1420)
Details
- Commit
- 7a3a0611a278
- Parent
- 5a6e9dac61d2
- Merge parent
- 547eb9ef7056
src/analyze_infer.cmodifiedView file
@@ -1257,10 +1257,19 @@
12571257
}12581258
}12591259
1260-
/* bare call inside a module/class body -> class method of that module/class */1261-
if (recv < 0 && g_cbody_class_id >= 0) {1262-
int smi = comp_cmethod_in_chain(c, g_cbody_class_id, name, NULL);1263-
if (smi >= 0) return method_call_ret(c, smi, id);1260+
/* bare call inside a module/class body -> class method of that module/class.1261+
Use the per-node enclosing-cbody: g_cbody_class_id is only set during the1262+
scope pass, not the inference fixpoint, so relying on it leaves a bare1263+
module-body cmethod call (e.g. `take(mk)` where mk is `def self.mk`) typed1264+
void. The scope pass records the enclosing cbody per node in node_cbody[id]1265+
(cf. analyze_scope.c, analyze.c which already read it during inference). */1266+
if (recv < 0) {1267+
int cbody = c->node_cbody[id];1268+
if (cbody < 0) cbody = g_cbody_class_id;1269+
if (cbody >= 0) {1270+
int smi = comp_cmethod_in_chain(c, cbody, name, NULL);1271+
if (smi >= 0) return method_call_ret(c, smi, id);1272+
}12641273
}12651274
/* bare call inside an instance_eval/exec block: dispatch on receiver class */12661275
if (recv < 0) {test/bare_module_body_cmethod_call.rbaddedView file
Loading diff…
test/bare_module_body_cmethod_call.rb.expectedaddedView file
Loading diff…