Commit 547eb9ef

547eb9ef7056Merged

Ori Pekelman <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

analyze: type a bare module/class-body cmethod call via node_cbody, not the scope-only global

A receiverless call in a class/module body (e.g. take(mk) where mk is def self.mk) resolved its callee through g_cbody_class_id, which is only set during the scope pass -- it is unset during the inference fixpoint where infer_call runs. So the bare call's result typed void: the qualified form M.mk propagated StrStrHash, but bare mk did not. The void arg then made the receiving method's param TY_UNKNOWN, tripping the unknown-param backstop (method dropped at emission -> undefined reference, or a declared void C error).

Read the per-node enclosing-cbody (node_cbody[id], recorded by the scope pass) instead, falling back to the global -- the same source analyze_scope.c and analyze.c already use to recover the cbody class during inference.

Repro (test/bare_module_body_cmethod_call.rb): a module-body R.new.take(mk) with a bare mk returning the {"" => ""}; delete("") typed-empty-hash idiom.

Surfaced compiling tep against master (matz/spinel#1420): the bare seed call set_cookie("", "", str_hash) voided str_hash, dropping Response#set_cookie. Full suite green (893 pass).

Details

Commit
547eb9ef7056
Parent
5a6e9dac61d2

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 the
1262+ scope pass, not the inference fixpoint, so relying on it leaves a bare
1263+ module-body cmethod call (e.g. `take(mk)` where mk is `def self.mk`) typed
1264+ 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) {