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 end
44294429 end
4430- # NilClass coercion methods. Issue #871. to_c / to_r / to_h
4431- # skipped: Complex / Rational unsupported, Hash needs typed
4432- # element judgement.
4430+ # NilClass coercion methods. Issue #871. to_c / to_r skipped:
4431+ # Complex / Rational unsupported.
44334432 if recv >= 0
44344433 recv_t_nil = infer_type(recv)
44354434 if recv_t_nil == "nil"
@@ -4443,6 +4442,12 @@
44434442 @needs_int_array = 1
44444443 return "int_array"
44454444 end
4445+ # nil.to_h is always the empty hash; the empty-hash literal types
4446+ # as str_int_hash, so match it.
4447+ if mname == "to_h"
4448+ @needs_str_int_hash = 1
4449+ return "str_int_hash"
4450+ end
44464451 if mname == "&"
44474452 return "bool"
44484453 end