Commit 9933a13d

9933a13de93bMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified

Description

fix(codegen,analyze): int/float/bool == nil is statically FALSE

v == nil on a value-type LHS (int / float / bool) fell through compile_eq's pointer branch into the raw (lc op rc) emit; compile_expr(NilNode) lowers to "0", so the compare collapsed to (int_val == 0). A stored 0 in a Hash<String, Int> then looked indistinguishable from nil at the != nil site -- the case reported in #521 where a real rank-0 entry in a BPE merges table was silently skipped.

Add value-type-vs-nil arms (both directions) to compile_eq that constant-fold to FALSE / TRUE while preserving the LHS evaluation for side effects via ((void)(lc), FALSE).

Surfacing one preexisting type-flow gap: ::ARGV[0] (ConstantPathNode receiver) was inferred as int because the ConstantPathNode arm didn't recognize ARGV the way the ConstantReadNode arm does, so the bracket lookup returned an int-typed expression. The prior raw (int == 0) emit accidentally matched (NULL == 0) semantics for the empty-argv case, masking the misroute. With the equality fix, ::ARGV[0] now needs the right type. Add an ARGV recognition arm in the ConstantPathNode infer branch.

Does NOT close #521. The deeper case (missing key vs stored 0 in a typed int hash) still needs nullable-read design -- when the slot is missing the runtime returns 0 from sp_StrIntHash_get and there is no in-band representation for "absent". The user- side workaround remains Hash#has_key? / Hash#fetch, both of which already work.

Refs #521

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

Details

Commit
9933a13de93b
Parent
884f68c19288

spinel_analyze.rbmodifiedView file

@@ -2095,6 +2095,16 @@
20952095 end
20962096 if t == "ConstantPathNode"
20972097 cpname = resolve_const_ref_name(nid)
2098+ # `::ARGV` resolves to the same top-level argv as `ARGV`. Without
2099+ # this, the root-scoped path fell through to the int default and
2100+ # `::ARGV[0]` typed as int -- bracket access then produced an int
2101+ # result and `::ARGV[0] == nil` lowered to a raw `(int == 0)`
2102+ # compare. Now that `int == nil` is statically FALSE (per #521),
2103+ # the wrong-type misroute became user-visible. Treat ARGV
2104+ # identically regardless of `::` prefix.
2105+ if cpname == "ARGV"
2106+ return "argv"
2107+ end
20982108 if cpname != ""
20992109 ci = find_const_idx(cpname)
21002110 if ci >= 0