Commit 4416079b

4416079b19ceMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

analyze: align Hash#invert fallback with the primary handler (PR #1019 follow-up)

Gemini flagged that the invert fallback in infer_method_name_type returned str_str_hash for int_str_hash — but inverting {int=>str} yields {str=>int}, which is str_int_hash, not str_str_hash. Mirror infer_operator_type's handler exactly: only str_str_hash inverts to itself; every other variant (including int_str_hash) falls through to poly_poly_hash. The fallback is normally shadowed by the operator handler, so this is a consistency/soundness fix in defensive code.

Refs #1019

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
4416079b19ce
Parent
677bf7109d2f

spinel_analyze.rbmodifiedView file

@@ -5322,9 +5322,13 @@
53225322 end
53235323 if mname == "invert"
53245324 # Hash#invert -- fallback; normally handled in infer_operator_type.
5325+ # Mirror that handler exactly: only str_str_hash inverts to itself
5326+ # (str=>str stays str=>str); every other variant goes to
5327+ # poly_poly_hash. int_str_hash (int=>str) inverts to str=>int, which
5328+ # is NOT str_str_hash, so it must fall through to poly_poly_hash.
53255329 if recv >= 0
53265330 rt_inv = infer_type(recv)
5327- if rt_inv == "str_str_hash" || rt_inv == "int_str_hash"
5331+ if rt_inv == "str_str_hash"
53285332 return "str_str_hash"
53295333 end
53305334 if is_hash_type(rt_inv) == 1