Commit 507158f6
507158f61403Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Type StringScanner#scan to a local as a String, not an Array
m = scanner.scan(/re/) declared m as sp_StrArray * -- the generic
String#scan arm (which returns an array of matches) fired for a
StringScanner receiver too, because infer_type's scan rule had no
receiver-type check. During scan_locals the receiver can be unresolved when
that rule runs, so the earlier StringScanner arm hasn't typed it yet.
Gate the String#scan str_array/poly_array arm on a string-like receiver, so StringScanner#scan (a single matched string) types the local correctly while String#scan on a real String still returns the array.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 507158f61403
- Parent
- 6d94883c4383
spinel_analyze.rbmodifiedView file
end end if mname == "scan" args_id_scan = @nd_arguments[nid] if args_id_scan >= 0 arg_ids_scan = get_args(args_id_scan) if arg_ids_scan.length > 0 && regexp_capture_status(arg_ids_scan[0]) != 0 @needs_rb_value = 1 return "poly_array" # String#scan returns an array of matches. Gate on a string-like # receiver so StringScanner#scan (which returns a single matched # string, handled by the strscan dispatch above) isn't mis-typed as # str_array -- the receiver can still be unresolved during scan_locals, # when the strscan arm hasn't fired yet. rt_scan_recv = recv >= 0 ? base_type(infer_type(recv)) : "" if recv < 0 || rt_scan_recv == "string" || rt_scan_recv == "mutable_str" args_id_scan = @nd_arguments[nid] if args_id_scan >= 0 arg_ids_scan = get_args(args_id_scan) if arg_ids_scan.length > 0 && regexp_capture_status(arg_ids_scan[0]) != 0 @needs_rb_value = 1 return "poly_array" end end return "str_array" end return "str_array" end if mname == "match" if recv >= 0test/string_scanner_scan_to_local.rbaddedView file
Loading diff…