From 5102ef80220e7c62de85a2e35d973517984e5e75 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 Dec 2025 01:33:33 +0900 Subject: [PATCH] vm.c: allow String subclasses to override []; ref #6675 Apply the same pattern as the Array/Hash fix: the OP_GETIDX optimization now only applies to instances of the String class itself. Subclasses fall back to method dispatch, allowing them to override the [] method. Co-authored-by: Claude --- src/vm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vm.c b/src/vm.c index 32e65351c..71bc8761a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1901,6 +1901,8 @@ RETRY_TRY_BLOCK: regs[a] = va; break; case MRB_TT_STRING: + /* optimize only for String class; subclasses may override [] */ + if (mrb_obj_class(mrb, va) != mrb->string_class) goto getidx_fallback; switch (mrb_type(vb)) { case MRB_TT_INTEGER: case MRB_TT_STRING: