Commit 0fd2b126
0fd2b126507dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: CaseNode/CaseMatchNode type inference unifies all branch types
Previously only the first when/in branch was used for type inference. Now all branches plus the else clause are collected and unified via unify_return_type, matching the IfNode improvement.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 0fd2b126507d
- Parent
- edc12fed179c
spinel_codegen.rbmodifiedView file
@@ -936,36 +936,66 @@
936936
return unify_return_type(types)937937
end938938
if t == "CaseMatchNode"939-
# Infer from first in branch939+
types = "".split(",")940940
conds = parse_id_list(@nd_conditions[nid])941-
if conds.length > 0942-
inid = conds.first941+
k = 0942+
while k < conds.length943+
inid = conds[k]943944
if @nd_type[inid] == "InNode"944945
ibody = @nd_body[inid]945946
if ibody >= 0946947
is = get_stmts(ibody)947948
if is.length > 0948-
return infer_type(is.last)949+
types.push(infer_type(is.last))949950
end950951
end951952
end953+
k = k + 1954+
end955+
ec = @nd_else_clause[nid]956+
if ec >= 0957+
ebody = @nd_body[ec]958+
if ebody >= 0959+
es = get_stmts(ebody)960+
if es.length > 0961+
types.push(infer_type(es.last))962+
end963+
end964+
end965+
if types.length > 0966+
return unify_return_type(types)952967
end953968
return "int"954969
end955970
if t == "CaseNode"956-
# Infer from first when branch971+
types = "".split(",")957972
conds = parse_id_list(@nd_conditions[nid])958-
if conds.length > 0959-
wid = conds.first973+
k = 0974+
while k < conds.length975+
wid = conds[k]960976
if @nd_type[wid] == "WhenNode"961977
wbody = @nd_body[wid]962978
if wbody >= 0963979
ws = get_stmts(wbody)964980
if ws.length > 0965-
return infer_type(ws.last)981+
types.push(infer_type(ws.last))966982
end967983
end968984
end985+
k = k + 1986+
end987+
ec = @nd_else_clause[nid]988+
if ec >= 0989+
ebody = @nd_body[ec]990+
if ebody >= 0991+
es = get_stmts(ebody)992+
if es.length > 0993+
types.push(infer_type(es.last))994+
end995+
end996+
end997+
if types.length > 0998+
return unify_return_type(types)969999
end9701000
return "int"9711001
end