Commit 17ba9952

17ba9952ee70Merged

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

Description

Empty array literal join/pack return an empty string

[].join and [].pack(...) fold to "" like the other empty-array-literal methods, instead of falling through to an unresolved call.

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

Details

Commit
17ba9952ee70
Parent
11c37624f910

src/codegen.cmodifiedView file

@@ -1567,6 +1567,7 @@
15671567 !strcmp(name, "min") || !strcmp(name, "max") ||
15681568 !strcmp(name, "pop") || !strcmp(name, "shift")) && argc == 0) { buf_puts(b, "SP_INT_NIL"); return; }
15691569 if ((!strcmp(name, "inspect") || !strcmp(name, "to_s")) && argc == 0) { buf_puts(b, "\"[]\""); return; }
1570+ if ((!strcmp(name, "join") || !strcmp(name, "pack")) && argc <= 1) { buf_puts(b, "(&(\"\\xff\")[1])"); return; }
15701571 if ((!strcmp(name, "flatten") || !strcmp(name, "compact") || !strcmp(name, "uniq") ||
15711572 !strcmp(name, "sort") || !strcmp(name, "reverse") || !strcmp(name, "dup") ||
15721573 !strcmp(name, "clone") || !strcmp(name, "to_a")) && argc <= 1) {