Commit 2daed172
2daed1720db9Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
analyze: handle module_function :sym form
module_function with symbol arguments marks the named instance methods as class methods rather than toggling a mode flag. Previously only the bare module_function (mode toggle) was implemented; the symbol form is common in module-function patterns like Strings::ANSI.sanitize.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 2daed1720db9
- Parent
- b4021bb463c7
src/analyze.cmodifiedView file
@@ -2026,7 +2026,25 @@
20262026
if (!sty) continue;20272027
if (!strcmp(sty, "CallNode") && nt_ref(nt, s, "receiver") < 0) {20282028
const char *nm = nt_str(nt, s, "name");2029-
if (nm && !strcmp(nm, "module_function")) { in_module_function = 1; continue; }2029+
if (nm && !strcmp(nm, "module_function")) {2030+
/* `module_function :m1, :m2` form: mark named methods */2031+
int an = 0;2032+
int anode = nt_ref(nt, s, "arguments");2033+
const int *aargs = anode >= 0 ? nt_arr(nt, anode, "arguments", &an) : NULL;2034+
if (an == 0) { in_module_function = 1; continue; }2035+
for (int ai = 0; ai < an; ai++) {2036+
const char *aty = nt_type(nt, aargs[ai]);2037+
const char *aval = NULL;2038+
if (aty && !strcmp(aty, "SymbolNode")) aval = nt_str(nt, aargs[ai], "value");2039+
if (!aval) continue;2040+
for (int mi = 0; mi < c->nscopes; mi++) {2041+
if (c->scopes[mi].class_id == ci && !c->scopes[mi].is_cmethod &&2042+
c->scopes[mi].name && !strcmp(c->scopes[mi].name, aval))2043+
c->scopes[mi].is_cmethod = 1;2044+
}2045+
}2046+
continue;2047+
}20302048
}20312049
if (!strcmp(sty, "DefNode") && in_module_function) {20322050
const char *mname = nt_str(nt, s, "name");