Commit d1af4f42

d1af4f4285c1Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): Integer#[] guard against ConstantRead/Path receivers

PR #185's Integer#[idx] bit-indexing fired on ENV["HOME"], ::ARGV[0], and similar constant receivers because infer_type's tail returns "int" for unrecognized constants. The bit-index handler ran before the constant's own []-dispatch, miscompiling ENV["HOME"] to (ENV >> "HOME") & 1.

Skip the bit-index branch when the receiver is a ConstantReadNode or ConstantPathNode so dispatch falls through to the existing ENV / ARGV / Dir handlers downstream.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
d1af4f4285c1
Parent
451ef39ee36c

spinel_codegen.rbmodifiedView file

@@ -17763,7 +17763,15 @@
1776317763 return rc
1776417764 end
1776517765 # Integer#[idx] — bit indexing. `n[k]` returns bit k of n.
17766+ # Skip when the receiver is a constant reference (ENV, STDIN,
17767+ # ::ARGV, ...) — those resolve their type to the int fallback at
17768+ # infer_type's tail and would otherwise eat the constant's own
17769+ # `[]` dispatch (e.g. ENV["HOME"] → getenv, ::ARGV[i] → argv).
1776617770 if mname == "[]"
17771+ recv_id = @nd_receiver[nid]
17772+ if recv_id >= 0 && (@nd_type[recv_id] == "ConstantReadNode" || @nd_type[recv_id] == "ConstantPathNode")
17773+ return ""
17774+ end
1776717775 args_id = @nd_arguments[nid]
1776817776 if args_id >= 0
1776917777 aargs = get_args(args_id)