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
} } /* bare call inside a module/class body -> class method of that module/class */ if (recv < 0 && g_cbody_class_id >= 0) { int smi = comp_cmethod_in_chain(c, g_cbody_class_id, name, NULL); if (smi >= 0) return method_call_ret(c, smi, id); /* bare call inside a module/class body -> class method of that module/class. Use the per-node enclosing-cbody: g_cbody_class_id is only set during the scope pass, not the inference fixpoint, so relying on it leaves a bare module-body cmethod call (e.g. `take(mk)` where mk is `def self.mk`) typed void. The scope pass records the enclosing cbody per node in node_cbody[id] (cf. analyze_scope.c, analyze.c which already read it during inference). */ if (recv < 0) { int cbody = c->node_cbody[id]; if (cbody < 0) cbody = g_cbody_class_id; if (cbody >= 0) { int smi = comp_cmethod_in_chain(c, cbody, name, NULL); if (smi >= 0) return method_call_ret(c, smi, id); } } /* bare call inside an instance_eval/exec block: dispatch on receiver class */ if (recv < 0) {test/bare_module_body_cmethod_call.rbaddedView file
Loading diff…
test/bare_module_body_cmethod_call.rb.expectedaddedView file
Loading diff…