Commit 61106976
61106976a2a6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix int-keyed hash inference, empty hash ivar writes, nested yield rename clobber, and when *splat/0r/0i
- analyze.c refine_locals: separate TY_INT
[]=(int-keyed hash) from is_push (array). Previouslyh[200]="OK"was widened to STR_ARRAY; now correctly infers INT_STR_HASH. - codegen.c InstanceVariableWriteNode: handle empty hash ivar write like empty array, emitting sp_Hash_new() for the inferred hash type.
- codegen.c emit_block_invoke: save/restore the rename table (g_ren_from/ g_ren_to) across block body emission. Previously a nested inline inside the block body would overwrite entries 0..sv-1, causing outer inlined loop increments to use the wrong renamed variable (e.g. _y16_i instead of _y15_i in nested repeat/my_times yield).
- codegen.c emit_case: add SplatNode handling for
when *arrconditions, dispatching to sp_{Int,Str,Float,Poly}Array_include. Add RationalNode handling (when 0r) and ImaginaryNode handling (when 0i).
Tests: 406 pass, 5 fail, 434 error (was 401/5/439).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 61106976a2a6
- Parent
- a9bec255b494
src/analyze.cmodifiedView file
@@ -1696,12 +1696,22 @@
16961696
else continue;16971697
16981698
TyKind before = *slot;1699-
if (is_push || kt == TY_INT) {1700-
/* array (a known string's `<<` is append, not push -- don't pollute) */1699+
if (is_push) {1700+
/* explicit push/append: definitely array */17011701
if (vt == TY_UNKNOWN) continue;17021702
if (*slot != TY_UNKNOWN && !ty_is_array(*slot)) continue;17031703
*slot = ty_unify(*slot, ty_array_of(vt));17041704
}1705+
else if (kt == TY_INT) {1706+
/* int key []=: if slot already array, leave it; otherwise infer int-keyed hash */1707+
if (vt == TY_UNKNOWN) continue;1708+
if (*slot != TY_UNKNOWN && ty_is_array(*slot)) continue;1709+
if (*slot != TY_UNKNOWN && !ty_is_hash(*slot)) continue;1710+
TyKind hv = ty_hash_of(TY_INT, vt);1711+
if (hv == TY_UNKNOWN) continue;1712+
if (*slot != TY_UNKNOWN && *slot != hv) continue;1713+
*slot = hv;1714+
}17051715
else if (kt == TY_STRING) {17061716
if (vt == TY_UNKNOWN) continue;17071717
TyKind hv = ty_hash_of(TY_STRING, vt);src/codegen.cmodifiedView file
Loading diff…