Commit 43165ee5
43165ee5c09bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Fix TY_UNKNOWN ivar hash when initialized with {} and int-keyed writes
When @h = {} and later @h[int_key] = value is used, the read-based hash promotion was blocked because @h = {} (HashNode) was treated as a "typed write". This prevented the ivar from being promoted to a typed hash variant.
Unlike @arr = [] (ArrayNode) which correctly blocks spurious hash promotion for array ivars, @h = {} is a hash and should allow usage-driven hash-type promotion from subsequent @h[k] reads and writes.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 43165ee5c09b
- Parent
- 63572713b0ce
src/analyze.cmodifiedView file
@@ -3803,10 +3803,11 @@
38033803
if (_wval < 0) continue;38043804
TyKind _wt = infer_type(c, _wval);38053805
if (_wt != TY_UNKNOWN && _wt != TY_NIL) { has_typed_write = 1; break; }3806-
/* @ivar = [] or @ivar = {} literal: this slot is an array/hash, not3807-
subject to hash-promotion from [] read or [0]= write. */3806+
/* @ivar = [] literal: this slot is an array, not subject to3807+
hash-promotion from [] read or [0]= write. Empty {} does NOT3808+
block promotion — the hash type is determined by key/value usage. */38083809
const char *_wvty = nt_type(nt, _wval);3809-
if (_wvty && (!strcmp(_wvty, "ArrayNode") || !strcmp(_wvty, "HashNode")))3810+
if (_wvty && !strcmp(_wvty, "ArrayNode"))38103811
has_typed_write = 1;38113812
}38123813
if (has_typed_write) continue;