summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-06-17 16:53:54 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-06-17 16:53:54 +0900
commit4fcb5e8e4fa687d5645ef49b26cfb61d7bee151b (patch)
tree9f0cf80ddd7adccc8734a59237db988b00efe9c5
parent63bafca7f5e1eb0e11f57875363ab5e5aa7cc8b6 (diff)
downloadmruby-4fcb5e8e4fa687d5645ef49b26cfb61d7bee151b.tar.gz
mruby-4fcb5e8e4fa687d5645ef49b26cfb61d7bee151b.zip
variable.c: add `skip` argument to skip `base` class in lookup.
`mrb_vm_const_get` function looks up the constant first in the base class, so that fallback `const_get` need not to search from the base.
-rw-r--r--src/variable.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/variable.c b/src/variable.c
index bf421955b..d89295229 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -766,13 +766,14 @@ mod_const_check(mrb_state *mrb, mrb_value mod)
}
static mrb_value
-const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym)
+const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym, mrb_bool skip)
{
struct RClass *c = base;
mrb_value v;
mrb_bool retry = FALSE;
mrb_value name;
+ if (skip) c = c->super;
L_RETRY:
while (c) {
if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv) {
@@ -794,7 +795,7 @@ MRB_API mrb_value
mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
{
mod_const_check(mrb, mod);
- return const_get(mrb, mrb_class_ptr(mod), sym);
+ return const_get(mrb, mrb_class_ptr(mod), sym, FALSE);
}
mrb_value
@@ -829,7 +830,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
}
proc = proc->upper;
}
- return const_get(mrb, c, sym);
+ return const_get(mrb, c, sym, TRUE);
}
MRB_API void