Commit db950a40

db950a409a08Merged

Yusuke Endoh <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

port: fix(codegen): String#index(sub, start) honours start offset

Backport of e098705 (cherry of master commit) — the 2-arg form of String#index dropped the start arg in the codegen branch. Apply the same compile_string_method_expr edit to my split codegen.rb.

The runtime helper sp_str_index_from already landed in lib/sp_runtime.h via the master rebase.

test/string_index_from passes.

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

Details

Commit
db950a409a08
Parent
67cc1950a9ea

spinel_codegen.rbmodifiedView file

@@ -12204,6 +12204,17 @@
1220412204 return rc
1220512205 end
1220612206 if mname == "index"
12207+ args_id_idx = @nd_arguments[nid]
12208+ if args_id_idx >= 0
12209+ a_idx = get_args(args_id_idx)
12210+ if a_idx.length >= 2
12211+ # `s.index(sub, start)` -- 2-arg form. Pre-fix this branch
12212+ # silently dropped `start` and re-emitted the 1-arg call,
12213+ # so successive `s.index(sub, dot1+1)` walks all returned
12214+ # the first match (instead of the next one after `dot1`).
12215+ return "sp_str_index_from(" + rc + ", " + compile_expr(a_idx[0]) + ", " + compile_expr(a_idx[1]) + ")"
12216+ end
12217+ end
1220712218 return "sp_str_index(" + rc + ", " + compile_arg0(nid) + ")"
1220812219 end
1220912220 if mname == "rindex"