Commit 2dcc23b2

2dcc23b2faa9Merged

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

Description

Struct instance methods: to_a/values/deconstruct, to_h, members

to_a/values/deconstruct build a poly array of the boxed member values; to_h builds a SymPolyHash {member_sym => value}; members lists the member symbols. Adds emit_boxed_text to box a C-text field expression.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
2dcc23b2faa9
Parent
9b0aeb69a5d7

src/analyze.cmodifiedView file

@@ -108,6 +108,13 @@
108108 }
109109 }
110110
111+ /* Struct instance methods */
112+ if (recv >= 0 && ty_is_object(rt) && c->classes[ty_object_class(rt)].is_struct) {
113+ if (!strcmp(name, "to_a") || !strcmp(name, "values") ||
114+ !strcmp(name, "deconstruct") || !strcmp(name, "members")) return TY_POLY_ARRAY;
115+ if (!strcmp(name, "to_h")) return TY_SYM_POLY_HASH;
116+ }
117+
111118 /* obj.method(...) -> the method's return type (walks the superclass chain) */
112119 if (recv >= 0 && ty_is_object(rt)) {
113120 int cid = ty_object_class(rt);