Commit d3901c76

d3901c763fd3Merged

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

Description

Poly [] dispatch: builtin-array arm only for an integer index

The builtin sp_IntArray_get arm in a poly-receiver [] dispatch is now gated on an integer index, so a string key (a hash/user-class lookup) no longer passes a string to sp_IntArray_get.

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

Details

Commit
d3901c763fd3
Parent
f1c25771efec

src/codegen.cmodifiedView file

@@ -1898,7 +1898,8 @@
18981898 and call the matching user method (or a builtin array `[]`), passing the
18991899 arguments evaluated once into temps. */
19001900 if (recv >= 0 && rt == TY_POLY && argc > 0) {
1901- int is_index = !strcmp(name, "[]") && argc == 1;
1901+ /* the builtin-array `[]` arm only applies to an integer index */
1902+ int is_index = !strcmp(name, "[]") && argc == 1 && comp_ntype(c, argv[0]) == TY_INT;
19021903 int ncand = 0;
19031904 for (int k = 0; k < c->nclasses; k++) {
19041905 int mi = comp_method_in_chain(c, k, name, NULL);