Commit ed62c432

ed62c43227abMerged

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

Description

Bind the block param to the key in Hash#fetch(k) { |key| ... }

The block form of Hash#fetch (run the block on a miss) compiled the block body without assigning the block param to the looked-up key, so a block that uses |key| computed from the param's declared default (0 for int-keyed hashes). Assign the param to the key before running the block.

This makes int-keyed hashes (int_int_hash / int_str_hash) correct. Sym/str-keyed variants additionally need the fetch-block param typed as the hash key type (it is currently scope-typed int); that part remains.

Refs #1339

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

Details

Commit
ed62c43227ab
Parent
bad7e0baeb8e

spinel_codegen.rbmodifiedView file

@@ -26593,6 +26593,13 @@
2659326593 emit(" } else {")
2659426594 @indent = @indent + 1
2659526595 push_scope
26596+ # Bind the block param to the missing key (`fetch(k) { |key| ... }`
26597+ # yields the looked-up key). Without this the param kept its
26598+ # declared default and the block computed from a zero/garbage key.
26599+ bp_fb = get_block_param(nid, 0)
26600+ if bp_fb != ""
26601+ emit(" lv_" + bp_fb + " = " + key_fb + ";")
26602+ end
2659626603 compile_body_into(@nd_body[@nd_block[nid]], tmp_fb, fi[0])
2659726604 pop_scope
2659826605 @indent = @indent - 1