Commit 080abef9
080abef961deMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(codegen,analyze): heterogeneous <int_array literal> << x lifts to poly_array
([1, 2] << "c") == [1, 2, "c"] should fold to true: CRuby's
<< accepts any element type and the resulting array stays
heterogeneous. Spinel's << arm for int_array recv pushed the
arg through sp_IntArray_push unconditionally, so a string arg
landed via pointer-from-int conversion and the result compared
unequal to the RHS poly_array literal.
Lift only when the recv is a direct ArrayNode literal (i.e. a
transient [1, 2]) and the arg type is non-int -- the lift
rebuilds the recv's elements as box_int(...) pushes into a fresh
poly_array, then pushes the boxed arg. Mirrored in the analyzer's
<< return-type rule so the surrounding == picks the
poly_array dispatch.
Scoped to ArrayNode literals so a stored ivar / local (the
optcarrot @slots = [nil] * N; @slots << ... shape) keeps its
existing observation-widening path and doesn't cascade typed-int
reads into poly.
Refs #619 puzzle 7. Closes the last #619 puzzle along with the rest of this issue's series (puzzles 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10).
Closes #619
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 080abef961de
- Parent
- e34a705af2d2
spinel_analyze.rbmodifiedView file
return "string" end # Array `<<` returns the recv (so `(arr << x) << y` chains). # `<int_array literal> << <non-int>` (`[1, 2] << "c"`) lifts to # poly_array at codegen so the result holds the heterogeneous # elements; mirror that in inference so the surrounding `==` # picks the poly_array dispatch arm rather than treating one # side as int_array. Issue #619 puzzle 7. if lt == "int_array" && @nd_type[recv] == "ArrayNode" args_id_p7 = @nd_arguments[nid] if args_id_p7 >= 0 aa_p7 = get_args(args_id_p7) if aa_p7.length > 0 at_p7 = infer_type(aa_p7[0]) if at_p7 != "int" && at_p7 != "bool" && at_p7 != "nil" @needs_rb_value = 1 @needs_gc = 1 return "poly_array" end end end end if is_array_type(lt) == 1 return lt endspinel_codegen.rbmodifiedView file
Loading diff…
test/int_array_literal_lshift_heterogeneous.rbaddedView file
Loading diff…
test/int_array_literal_lshift_heterogeneous.rb.expectedaddedView file
Loading diff…