Commit 7780fff2

7780fff2c6e8Merged

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

Description

analyze,codegen,runtime: poly_array.zip returns poly_array_ptr_array

Mixed-type `[1, "a"].zip([2, "b"])` reported the result as int_array_ptr_array; the inspect path then walked each sp_RbVal element as a 16-int blob, printing the box bytes literally.

  • analyze: poly_array.zip(poly_array) → poly_array_ptr_array (was falling through to int_array_ptr_array).
  • runtime: sp_PolyArrayPtrArray_inspect mirrors the existing StrArrayPtrArray / FloatArrayPtrArray helpers (declared after sp_PolyArray_inspect's forward decl since sp_PolyArray is defined later in the header).
  • codegen: inspect dispatch maps poly_array_ptr_array to the new helper.

Fixes #966

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
7780fff2c6e8
Parent
85fb3dce7143

lib/sp_runtime.hmodifiedView file

@@ -1814,6 +1814,8 @@
18141814 static sp_PtrArray*sp_IntArray_permutation(sp_IntArray*a,mrb_int k){sp_PtrArray*out=sp_PtrArray_new();if(!a||k<0||k>a->len)return out;sp_IntArray*used=sp_IntArray_new();for(mrb_int i=0;i<a->len;i++)sp_IntArray_push(used,0);sp_IntArray*acc=sp_IntArray_new();sp_int_permutation_recur(a,k,used,acc,out);return out;}
18151815 static const char*sp_FloatArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_FloatArray_inspect((sp_FloatArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}
18161816 static const char*sp_StrArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_StrArray_inspect((sp_StrArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}
1817+/* sp_PolyArrayPtrArray_inspect lives below sp_PolyArray_inspect's
1818+ forward declaration (sp_PolyArray isn't defined until ~2542). */
18171819 static const char*sp_SymArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_SymArray_inspect((sp_IntArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}
18181820 /* issue #526: join for a sp_PtrArray of sp_String* (mutable_str_ptr_array).
18191821 Sibling to sp_StrArray_join, but takes advantage of sp_String's known
@@ -2827,6 +2829,7 @@
28272829 accumulator boxes each inner poly_array element), but the
28282830 sp_PolyArray_inspect body lives a few lines below. */
28292831 static const char *sp_PolyArray_inspect(sp_PolyArray *a);
2832+static const char*sp_PolyArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_PolyArray_inspect((sp_PolyArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}
28302833
28312834 /* Object#inspect for a tagged sp_RbVal. Dispatches on the runtime tag;
28322835 each branch reuses the matching primitive inspect helper. Falls back