Commit c15716c6
c15716c6d7b7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Hash#merge (StrInt/StrPoly/SymPoly) and KeywordHashNode as a hash literal
merge(other) for the runtime-backed hash variants; merge/dup/clone infer the receiver type. A KeywordHashNode (bare keyword args, e.g. h.merge(a: 1)) is treated as a hash literal in inference and codegen.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- c15716c6d7b7
- Parent
- d05a7a878e28
src/analyze.cmodifiedView file
@@ -384,6 +384,7 @@
384384
!strcmp(name, "count")) return TY_INT;385385
if (!strcmp(name, "keys")) return ty_array_of(ty_hash_key(rt));386386
if (!strcmp(name, "values")) return ty_array_of(ty_hash_val(rt));387+
if (!strcmp(name, "merge") || !strcmp(name, "dup") || !strcmp(name, "clone")) return rt;387388
if (!strcmp(name, "has_key?") || !strcmp(name, "key?") ||388389
!strcmp(name, "include?") || !strcmp(name, "member?") ||389390
!strcmp(name, "has_value?") || !strcmp(name, "value?") ||@@ -557,7 +558,7 @@
557558
for (int k = 0; k < n; k++) e = ty_unify(e, infer_type(c, els[k]));558559
return ty_array_of(e);559560
}560-
if (!strcmp(ty, "HashNode")) {561+
if (!strcmp(ty, "HashNode") || !strcmp(ty, "KeywordHashNode")) {561562
int n = 0;562563
const int *els = nt_arr(nt, id, "elements", &n);563564
if (n == 0) return TY_UNKNOWN;src/codegen.cmodifiedView file
Loading diff…