Commit e50b09a9

e50b09a972cdMerged

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

Description

Hash#fetch(key){|k|} yields the looked-up key to the block

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

Details

Commit
e50b09a972cd
Parent
d8f1545c1a81

src/analyze.cmodifiedView file

@@ -1888,6 +1888,15 @@
18881888 continue;
18891889 }
18901890
1891+ /* hash.fetch(key) { |k| } binds the looked-up key */
1892+ if (!strcmp(name, "fetch") && ty_is_hash(rt)) {
1893+ Scope *fs = comp_scope_of(c, block);
1894+ LocalVar *kp = scope_local_intern(fs, p0); kp->is_block_param = 1;
1895+ TyKind km = ty_unify(kp->type, ty_hash_key(rt));
1896+ if (km != kp->type) { kp->type = km; changed = 1; }
1897+ continue;
1898+ }
1899+
18911900 /* hash.each / each_pair { |k, v| } binds two params */
18921901 if ((!strcmp(name, "each") || !strcmp(name, "each_pair") || !strcmp(name, "map") ||
18931902 !strcmp(name, "collect") || !strcmp(name, "flat_map") || !strcmp(name, "select") ||