Commit 6047c90e
6047c90ee1edMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · +2 added · ~3 modified
Description
Type Class values in collections as poly, not int
A Class object stored in a Hash value or Array element was inferred as int, so codegen emitted an int-typed container (str_int_hash / int_array) and stored the sp_Class struct through the integer path -- a C type mismatch (incompatible type for sp_StrIntHash_set / sp_IntArray_push). A Class in a scalar variable was already handled; only collections mis-typed it.
Add a class arm to the array-element and hash-value type inference, in
both the analyze and codegen passes (which mirror each other), so a
class-valued collection routes to poly storage (poly_array /
*_poly_hash). Add a class case to box_non_nullable_value_to_poly so
the element boxes via sp_box_class rather than the sp_box_int default,
and the missing SP_TAG_CLASS arm to sp_poly_puts so a class read back
out of poly storage prints its name instead of its cls_id.
Closes #1337
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 6047c90ee1ed
- Parent
- 2874f4170de9
lib/sp_runtime.hmodifiedView file
return buf;}static sp_RbVal sp_box_poly_array(void *p) { return sp_box_obj(p, SP_BUILTIN_POLY_ARRAY); }static const char *sp_class_to_s(sp_Class c); /* fwd decl: sp_poly_puts' SP_TAG_CLASS arm */static inline void sp_poly_puts(sp_RbVal v) { switch (v.tag) { case SP_TAG_INT: printf("%lld\n", (long long)v.v.i); break; case SP_TAG_NIL: putchar('\n'); break; case SP_TAG_SYM: { const char *_ss = sp_sym_to_s((sp_sym)v.v.i); fputs(_ss, stdout); putchar('\n'); break; } case SP_TAG_ENCODING: { const char *_es = v.v.s ? v.v.s : sp_str_empty; fputs(_es, stdout); putchar('\n'); break; } case SP_TAG_CLASS: { sp_Class _c = {v.v.i}; fputs(sp_class_to_s(_c), stdout); putchar('\n'); break; } case SP_TAG_OBJ: { /* MRI's `puts arr` iterates an Array, printing one element per line (using to_s on each); a non-Array OBJ falls back tospinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/class_in_collection.rbaddedView file
Loading diff…
test/class_in_collection.rb.expectedaddedView file
Loading diff…