Commit 2e186d18

2e186d18c766Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Preserve Float values stored in a Hash

A hash literal with Float values had no dedicated typed variant, so infer_hash_val_type fell through to the str_int_hash default and the fractional part was truncated to mrb_int on read ({"k"=>52.9} read back as 52). Route float-valued literals to poly storage (str_poly_hash / sym_poly_hash / poly_poly_hash by key shape) so each slot keeps its own tag, mirroring the existing poly/symbol-value arms. The incremental empty-hash-then-[]= path already promoted floats to poly via scan_locals; this aligns the literal path with it.

Fixes #1258

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

Details

Commit
2e186d18c766
Parent
82f11332444d

spinel_analyze.rbmodifiedView file

@@ -3107,6 +3107,20 @@
31073107 end
31083108 return "str_poly_hash"
31093109 end
3110+ # Float values have no dedicated typed-hash variant; route them
3111+ # through poly storage so each slot keeps its own tag rather than
3112+ # falling through to the str_int_hash default (which truncates the
3113+ # float to mrb_int on read).
3114+ if first_vt == "float"
3115+ @needs_rb_value = 1
3116+ if all_sym_keys == 1
3117+ return "sym_poly_hash"
3118+ end
3119+ if all_int_keys == 1
3120+ return "poly_poly_hash"
3121+ end
3122+ return "str_poly_hash"
3123+ end
31103124 # Inner hash/array values need a poly outer so each pointer
31113125 # can carry its own cls_id through SP_TAG_OBJ.
31123126 if is_hash_type(first_vt) == 1 || is_array_type(first_vt) == 1