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
end if t == "ConstantPathNode" cpname = resolve_const_ref_name(nid) # `::ARGV` resolves to the same top-level argv as `ARGV`. Without # this, the root-scoped path fell through to the int default and # `::ARGV[0]` typed as int -- bracket access then produced an int # result and `::ARGV[0] == nil` lowered to a raw `(int == 0)` # compare. Now that `int == nil` is statically FALSE (per #521), # the wrong-type misroute became user-visible. Treat ARGV # identically regardless of `::` prefix. if cpname == "ARGV" return "argv" end if cpname != "" ci = find_const_idx(cpname) if ci >= 0spinel_codegen.rbmodifiedView file
Loading diff…
test/int_eq_nil_strict.rbaddedView file
Loading diff…
test/int_eq_nil_strict.rb.expectedaddedView file
Loading diff…