Commit 290b4625
290b4625ec41Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: infer return types of user-defined class methods
Class methods like Point.origin that call ClassName.new were not having their return types inferred, causing local variables to default to int. This adds lookup of class method return types in infer_constant_recv_type.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 290b4625ec41
- Parent
- b183d910bd09
spinel_codegen.rbmodifiedView file
@@ -1731,6 +1731,29 @@
17311731
end17321732
end17331733
end1734+
# User-defined class methods1735+
if recv >= 01736+
if @nd_type[recv] == "ConstantReadNode"1737+
rcname = @nd_name[recv]1738+
ci2 = find_class_idx(rcname)1739+
if ci2 >= 01740+
if mname == "new"1741+
return "obj_" + rcname1742+
end1743+
cmnames = @cls_cmeth_names[ci2].split(";")1744+
cm_returns = @cls_cmeth_returns[ci2].split(";")1745+
cj = 01746+
while cj < cmnames.length1747+
if cmnames[cj] == mname1748+
if cj < cm_returns.length && cm_returns[cj] != "" && cm_returns[cj] != "int"1749+
return cm_returns[cj]1750+
end1751+
end1752+
cj = cj + 11753+
end1754+
end1755+
end1756+
end17341757
# StringIO methods17351758
if recv >= 017361759
rt = infer_type(recv)