Commit e8762348
e87623480894Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #498 from ryanseys/rs-fix-toplevel-kwrest-block-ptypes
fix(analyze): collect kwrest/posts ptypes for top-level methods
Details
- Commit
- e87623480894
- Parent
- d3940757958e
- Merge parent
- 153e9f28e04d
spinel_analyze.rbmodifiedView file
@@ -8703,70 +8703,16 @@
87038703
mname = @nd_name[nid]87048704
body_id = @nd_body[nid]87058705
params_str = collect_params_str(nid)8706-
ptypes_str = ""8706+
# Use the shared ptypes builder so kwrest (`**kw`) and post-rest8707+
# required params (`def f(*r, x, y)`) get slots that match the8708+
# names emitted by collect_params_str above. An earlier inline8709+
# build here omitted both, leaving param_names.length one (or8710+
# more) ahead of param_types.length — the per-method scope build8711+
# in infer_function_body_call_types then pushed nil into the8712+
# scope_types array for any missing slot, which later tripped8713+
# base_type / unify_call_types when a body referenced that local.8714+
ptypes_str = collect_ptypes_str(nid, -1)87078715
defaults_str = collect_defaults_str(nid)8708-
8709-
# Infer param types from defaults8710-
params = @nd_parameters[nid]8711-
if params >= 08712-
reqs = parse_id_list(@nd_requireds[params])8713-
opts = parse_id_list(@nd_optionals[params])8714-
kws = parse_id_list(@nd_keywords[params])8715-
k = 08716-
while k < reqs.length8717-
if ptypes_str != ""8718-
ptypes_str = ptypes_str + ","8719-
end8720-
ptypes_str = ptypes_str + "int"8721-
k = k + 18722-
end8723-
k = 08724-
while k < opts.length8725-
if ptypes_str != ""8726-
ptypes_str = ptypes_str + ","8727-
end8728-
def_id = @nd_expression[opts[k]]8729-
if def_id >= 08730-
ptypes_str = ptypes_str + infer_type(def_id)8731-
else8732-
ptypes_str = ptypes_str + "int"8733-
end8734-
k = k + 18735-
end8736-
k = 08737-
while k < kws.length8738-
if ptypes_str != ""8739-
ptypes_str = ptypes_str + ","8740-
end8741-
def_id = @nd_expression[kws[k]]8742-
if def_id >= 08743-
ptypes_str = ptypes_str + infer_type(def_id)8744-
else8745-
ptypes_str = ptypes_str + "int"8746-
end8747-
k = k + 18748-
end8749-
# Rest param (splat)8750-
rest = @nd_rest[params]8751-
if rest >= 08752-
if @nd_type[rest] == "RestParameterNode"8753-
if ptypes_str != ""8754-
ptypes_str = ptypes_str + ","8755-
end8756-
ptypes_str = ptypes_str + "int_array"8757-
end8758-
end8759-
# Block param (&block)8760-
blk = @nd_block[params]8761-
if blk >= 08762-
if @nd_type[blk] == "BlockParameterNode"8763-
if ptypes_str != ""8764-
ptypes_str = ptypes_str + ","8765-
end8766-
ptypes_str = ptypes_str + "proc"8767-
end8768-
end8769-
end87708716
87718717
@meth_names.push(mname)87728718
@meth_param_names.push(params_str)test/toplevel_kwrest_block_param.rbaddedView file
Loading diff…
test/toplevel_kwrest_block_param.rb.expectedaddedView file
Loading diff…