Commit b0c1423a
b0c1423a0eebMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +2 added
Description
test: hash-each param narrowing regression guard (#408)
Lock in the body-walker fix that landed in 9ca01d7 and was
ported to spinel_analyze.rb in 02003ad. Re-runs the exact
confirmation snippet from #408's ack comment -- a class
method whose only signal on its hash param is h.each |k, v|
inside the body, with str_str_hash and str_int_hash variants.
Without this guard the narrow path is exposed to silent regressions from future refactors of the each-body walker; the original symptom is a C-compile error, not a runtime miscompare, so a unit-style test catches it.
Closes #408 Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b0c1423a0eeb
- Parent
- c6c932f37a90
test/hash_each_param_narrow.rbaddedView file
1+
# Issue #408. Regression guard for the hash-each body-walker2+
# narrow path (9ca01d7 + analyze-side port in 02003ad).3+
#4+
# Pre-fix shape: a class method whose only signal on its hash5+
# param is `h.each |k, v|` inside the body left `h` typed as6+
# poly_poly_hash, made `k` / `v` poly, and the str-concat7+
# `\"\\\"\" + k + \"\\\":\"` cascaded into compile errors at the C8+
# layer ("passing sp_RbVal to parameter of incompatible type9+
# 'const char *'").10+
#11+
# Post-fix: the body-walker harvests usage signals -- here, k/v12+
# both flowing into str-concat -- and narrows the param to13+
# str_str_hash (or str_int_hash when v is int-shaped). Both14+
# compile clean and produce the expected output.15+
#16+
# This test re-runs the exact confirmation snippet Ori posted on17+
# #408; closing the issue without a regression guard would leave18+
# the narrow path exposed to silent regressions on future19+
# refactors to the each-body walker.20+
21+
class Encoder22+
def self.from_str_hash(h)23+
out = "{"24+
first = true25+
h.each do |k, v|26+
out += "," unless first27+
first = false28+
out += "\"" + k + "\":\"" + v + "\""29+
end30+
out + "}"31+
end32+
33+
def self.from_int_hash(h)34+
out = "{"35+
first = true36+
h.each do |k, v|37+
out += "," unless first38+
first = false39+
out += "\"" + k + "\":" + v.to_s40+
end41+
out + "}"42+
end43+
end44+
45+
puts Encoder.from_str_hash({"name" => "alice", "city" => "NYC"})46+
puts Encoder.from_int_hash({"a" => 1, "b" => 2, "c" => 3})test/hash_each_param_narrow.rb.expectedaddedView file
Loading diff…