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-rest
8707+ # required params (`def f(*r, x, y)`) get slots that match the
8708+ # names emitted by collect_params_str above. An earlier inline
8709+ # build here omitted both, leaving param_names.length one (or
8710+ # more) ahead of param_types.length — the per-method scope build
8711+ # in infer_function_body_call_types then pushed nil into the
8712+ # scope_types array for any missing slot, which later tripped
8713+ # 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 defaults
8710- params = @nd_parameters[nid]
8711- if params >= 0
8712- 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 = 0
8716- while k < reqs.length
8717- if ptypes_str != ""
8718- ptypes_str = ptypes_str + ","
8719- end
8720- ptypes_str = ptypes_str + "int"
8721- k = k + 1
8722- end
8723- k = 0
8724- while k < opts.length
8725- if ptypes_str != ""
8726- ptypes_str = ptypes_str + ","
8727- end
8728- def_id = @nd_expression[opts[k]]
8729- if def_id >= 0
8730- ptypes_str = ptypes_str + infer_type(def_id)
8731- else
8732- ptypes_str = ptypes_str + "int"
8733- end
8734- k = k + 1
8735- end
8736- k = 0
8737- while k < kws.length
8738- if ptypes_str != ""
8739- ptypes_str = ptypes_str + ","
8740- end
8741- def_id = @nd_expression[kws[k]]
8742- if def_id >= 0
8743- ptypes_str = ptypes_str + infer_type(def_id)
8744- else
8745- ptypes_str = ptypes_str + "int"
8746- end
8747- k = k + 1
8748- end
8749- # Rest param (splat)
8750- rest = @nd_rest[params]
8751- if rest >= 0
8752- if @nd_type[rest] == "RestParameterNode"
8753- if ptypes_str != ""
8754- ptypes_str = ptypes_str + ","
8755- end
8756- ptypes_str = ptypes_str + "int_array"
8757- end
8758- end
8759- # Block param (&block)
8760- blk = @nd_block[params]
8761- if blk >= 0
8762- if @nd_type[blk] == "BlockParameterNode"
8763- if ptypes_str != ""
8764- ptypes_str = ptypes_str + ","
8765- end
8766- ptypes_str = ptypes_str + "proc"
8767- end
8768- end
8769- end
87708716
87718717 @meth_names.push(mname)
87728718 @meth_param_names.push(params_str)