Commit a7befaff

a7befaffb3ecMerged

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

Description

String#encoding as an Encoding value

str.encoding returns a boxed UTF-8 Encoding (spinel is UTF-8 throughout); puts and .class route through the existing poly Encoding arms, and the str.encoding.name chain resolves to the encoding name. The name handling is scoped to the .encoding chain so it does not disturb .name on other poly receivers (Symbol, Struct members).

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

Details

Commit
a7befaffb3ec
Parent
1f14a304d288

src/analyze.cmodifiedView file

@@ -721,8 +721,15 @@
721721 !strcmp(name, "empty?")) return TY_BOOL;
722722 }
723723
724+ /* <str>.encoding.name -> the encoding name string */
725+ if (!strcmp(name, "name") && argc == 0 && recv >= 0 &&
726+ nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") &&
727+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "encoding"))
728+ return TY_STRING;
729+
724730 /* string receiver methods */
725731 if (recv >= 0 && rt == TY_STRING) {
732+ if (!strcmp(name, "encoding") && argc == 0) return TY_POLY; /* an Encoding value */
726733 if (!strcmp(name, "upcase") || !strcmp(name, "downcase") ||
727734 !strcmp(name, "capitalize") || !strcmp(name, "reverse") ||
728735 !strcmp(name, "strip") || !strcmp(name, "lstrip") ||