Commit d1156d77
d1156d779150Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Implement NilClass#to_h
nil.to_h was unresolved (emitting 0). CRuby returns an empty hash;
emit one typed as str_int_hash to match the empty-hash literal.
Fixes #1223
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- d1156d779150
- Parent
- 8afc7106f008
spinel_analyze.rbmodifiedView file
@@ -4427,9 +4427,8 @@
44274427
return "proc"44284428
end44294429
end4430-
# NilClass coercion methods. Issue #871. to_c / to_r / to_h4431-
# skipped: Complex / Rational unsupported, Hash needs typed4432-
# element judgement.4430+
# NilClass coercion methods. Issue #871. to_c / to_r skipped:4431+
# Complex / Rational unsupported.44334432
if recv >= 044344433
recv_t_nil = infer_type(recv)44354434
if recv_t_nil == "nil"@@ -4443,6 +4442,12 @@
44434442
@needs_int_array = 144444443
return "int_array"44454444
end4445+
# nil.to_h is always the empty hash; the empty-hash literal types4446+
# as str_int_hash, so match it.4447+
if mname == "to_h"4448+
@needs_str_int_hash = 14449+
return "str_int_hash"4450+
end44464451
if mname == "&"44474452
return "bool"44484453
endspinel_codegen.rbmodifiedView file
Loading diff…
test/nil_to_h.rbaddedView file
Loading diff…
test/nil_to_h.rb.expectedaddedView file
Loading diff…