Commit 7188d67c
7188d67c0a06Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): infer return type at module class-method call sites
A module-level singleton method (module M; def self.X; ...; end) whose
body returned a non-int value was typed as mrb_int at every call site.
Capturing to a local emitted mrb_int = const char * (a -Wint-conversion
warning, hard error under -Werror); inline puts M.greet compiled but
printed the pointer as an integer. The class form already worked because
infer_constant_recv_type walks @cls_cmeth_returns for class methods,
but module class methods live in the top-level @meth_* table as
<Mod>_cls_<method> with no parallel lookup.
Adds the missing module branch alongside the class one, mirroring its
shape (same != "" && != "int" filter so callers still fall through to
name-based heuristics for genuinely-int returns).
The ENV side-finding flagged in #127's "possibly-related" section
(ENV["USE_MEM"] == "1" always false) is independent of this fix and
still reproduces; will spin off as its own issue.
Closes #127
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 7188d67c0a06
- Parent
- 136bb797f367
spinel_codegen.rbmodifiedView file
cj = cj + 1 end end # Issue #127: same lookup for module class methods. They live in # the top-level @meth_* table as `<Mod>_cls_<method>`, not in # @cls_cmeth_* (which is class-only). Without this branch every # `Module.cls_method` call inferred as int regardless of return # type, so `s = M.greet` declared `lv_s` as mrb_int even though # `sp_M_cls_greet()` returns `const char *`. if module_name_exists(rcname) == 1 mfi = find_method_idx(rcname + "_cls_" + mname) if mfi >= 0 && mfi < @meth_return_types.length mrt = @meth_return_types[mfi] if mrt != "" && mrt != "int" return mrt end end end end end # StringIO methodstest/module_cls_method_string_return.rbaddedView file
Loading diff…