From d65fb765ef358357a75b745b68296c7fd78dff72 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 Dec 2025 01:31:22 +0900 Subject: [PATCH] vm.c: allow Array subclasses to override []; ref #6675 Apply the same pattern as the Hash fix: the OP_GETIDX optimization now only applies to instances of the Array 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 b74b70405..32e65351c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1880,6 +1880,8 @@ RETRY_TRY_BLOCK: mrb_value va = regs[a], vb = regs[a+1]; switch (mrb_type(va)) { case MRB_TT_ARRAY: + /* optimize only for Array class; subclasses may override [] */ + if (mrb_obj_class(mrb, va) != mrb->array_class) goto getidx_fallback; if (!mrb_integer_p(vb)) goto getidx_fallback; else { mrb_int idx = mrb_integer(vb);