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-walker
2+# narrow path (9ca01d7 + analyze-side port in 02003ad).
3+#
4+# Pre-fix shape: a class method whose only signal on its hash
5+# param is `h.each |k, v|` inside the body left `h` typed as
6+# poly_poly_hash, made `k` / `v` poly, and the str-concat
7+# `\"\\\"\" + k + \"\\\":\"` cascaded into compile errors at the C
8+# layer ("passing sp_RbVal to parameter of incompatible type
9+# 'const char *'").
10+#
11+# Post-fix: the body-walker harvests usage signals -- here, k/v
12+# both flowing into str-concat -- and narrows the param to
13+# str_str_hash (or str_int_hash when v is int-shaped). Both
14+# compile clean and produce the expected output.
15+#
16+# This test re-runs the exact confirmation snippet Ori posted on
17+# #408; closing the issue without a regression guard would leave
18+# the narrow path exposed to silent regressions on future
19+# refactors to the each-body walker.
20+
21+class Encoder
22+ def self.from_str_hash(h)
23+ out = "{"
24+ first = true
25+ h.each do |k, v|
26+ out += "," unless first
27+ first = false
28+ out += "\"" + k + "\":\"" + v + "\""
29+ end
30+ out + "}"
31+ end
32+
33+ def self.from_int_hash(h)
34+ out = "{"
35+ first = true
36+ h.each do |k, v|
37+ out += "," unless first
38+ first = false
39+ out += "\"" + k + "\":" + v.to_s
40+ end
41+ out + "}"
42+ end
43+end
44+
45+puts Encoder.from_str_hash({"name" => "alice", "city" => "NYC"})
46+puts Encoder.from_int_hash({"a" => 1, "b" => 2, "c" => 3})