Commit 34ff4c89
34ff4c895448Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 5 files · +2 added · ~3 modified
Description
fix(analyze,codegen,runtime): body-usage widen int|nil param to poly for .include?
Sam Ruby's #558. Sibling of #552 for the other ambiguous-
receiver method that exists on String / Array / Hash / Range
but NOT on Integer. Pre-fix cols.include?(:updated_at) on
an int/nil-defaulted param produced "cannot resolve call to
'include?' on int (emitting 0)" and silently returned 0,
breaking ActiveRecord::Base#fill_timestamps and view-helper
opts.include?(:disabled) checks in roundhouse's framework
runtime.
Three pieces:
-
is_lengthlike_only_method (analyze) now matches
include?alongside length / size / empty?. Same body proof: a param the body calls include? on is provably not an Integer, so widening to flat poly is sound. -
emit_poly_builtin_dispatch (codegen) gains include? arms keyed by the arg type. Array variants use the existing sp_*Array_include helpers (sym_array shares sp_IntArray_include since sym ids store as mrb_int); Hash variants alias include? -> has_key? per CRuby. SP_TAG_STR include? in compile_poly_method_call fires for string args (CRuby's String#include? takes a substring; non-string args TypeError at runtime, so the result temp stays at its default).
-
New sp_PolyArray_include runtime helper. Iterates the sp_RbVal array and compares via sp_poly_eq, mirroring the *Array_include pattern but with poly element type.
-
scan_for_dig_usage's pre-scan extended to also arm @needs_sym_int_hash / @needs_sym_str_hash / @needs_sym_poly_hash / @needs_str_poly_hash when an
include?call appears with a symbol or string arg. Mirrors the dig-arm coverage from #555 case 07 since the typedef-emit pass runs before compile-time@needs_flags would otherwise flip.
Verified: 527 tests pass (including a new discriminator that prints false/false/false/false/false pre-fix and false/true/false/true/false post-fix), optcarrot checksum 59662 preserved.
Closes #558
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 34ff4c895448
- Parent
- 33a04d660349
lib/sp_runtime.hmodifiedView file
} return TRUE;}static mrb_bool sp_PolyArray_include(sp_PolyArray *a, sp_RbVal v) { if (!a) return FALSE; for (mrb_int i = 0; i < a->len; i++) { if (sp_poly_eq(a->data[i], v)) return TRUE; } return FALSE;}/* Mark the embedded GC reference inside an sp_RbVal (string or obj). Used as the scan hook for containers that store polymorphic values. */spinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/param_include_body_widen.rbaddedView file
Loading diff…
test/param_include_body_widen.rb.expectedaddedView file
Loading diff…