From 9c9be44a980c3c869895fbf3ee2bc813b70e4684 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 5 Mar 2023 20:32:56 +0900 Subject: [PATCH] Don't switch constant search path from modules to Object Previously, for example, it was possible to retrieve the `String` class as follows: ```console % bin/mruby -e 'p Comparable::Enumerable::Errno::GC::Kernel::Math::ObjectSpace::String' String ``` Note that this patch affects the API function `mrb_const_get()`. --- src/variable.c | 2 +- test/t/syntax.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/variable.c b/src/variable.c index be27f0eda..3088783ec 100644 --- a/src/variable.c +++ b/src/variable.c @@ -785,7 +785,7 @@ L_RETRY: c = c->super; if (!skip && c == mrb->object_class) break; } - if (!retry && base->tt == MRB_TT_MODULE) { + if (!retry && base->tt == MRB_TT_MODULE && skip) { c = mrb->object_class; retry = TRUE; goto L_RETRY; diff --git a/test/t/syntax.rb b/test/t/syntax.rb index 7de861132..538c97418 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -211,6 +211,7 @@ assert('Nested const reference') do end assert_equal "hello world", Syntax4Const::CONST1 assert_equal "hello world", Syntax4Const::Const2.new.const1 + assert_raise(NameError) { Syntax4Const::Object } end assert('Abbreviated variable assignment as returns') do