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 end
17321732 end
17331733 end
1734+ # User-defined class methods
1735+ if recv >= 0
1736+ if @nd_type[recv] == "ConstantReadNode"
1737+ rcname = @nd_name[recv]
1738+ ci2 = find_class_idx(rcname)
1739+ if ci2 >= 0
1740+ if mname == "new"
1741+ return "obj_" + rcname
1742+ end
1743+ cmnames = @cls_cmeth_names[ci2].split(";")
1744+ cm_returns = @cls_cmeth_returns[ci2].split(";")
1745+ cj = 0
1746+ while cj < cmnames.length
1747+ if cmnames[cj] == mname
1748+ if cj < cm_returns.length && cm_returns[cj] != "" && cm_returns[cj] != "int"
1749+ return cm_returns[cj]
1750+ end
1751+ end
1752+ cj = cj + 1
1753+ end
1754+ end
1755+ end
1756+ end
17341757 # StringIO methods
17351758 if recv >= 0
17361759 rt = infer_type(recv)