From ac112f2b5dc7e16ccde8f048be80946187a033b0 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Wed, 6 Nov 2019 01:47:32 -0500 Subject: Avoid top-level search for nested constant reference from nil in defined? Fixes [Bug #16332] Constant access was changed to no longer allow top-level constant access through `nil`, but `defined?` wasn't changed at the same time to stay consistent. Use a separate defined type to distinguish between a constant referenced from the current lexical scope and one referenced from another namespace. --- vm_insnhelper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'vm_insnhelper.c') diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 5c83c343cc..205b4d915f 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3477,11 +3477,14 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ break; } case DEFINED_CONST: + case DEFINED_CONST_FROM: { + bool allow_nil = type == DEFINED_CONST; klass = v; - if (vm_get_ev_const(ec, klass, SYM2ID(obj), 1, 1)) { + if (vm_get_ev_const(ec, klass, SYM2ID(obj), allow_nil, true)) { expr_type = DEFINED_CONST; } break; + } case DEFINED_FUNC: klass = CLASS_OF(v); if (rb_method_boundp(klass, SYM2ID(obj), 0)) { -- cgit v1.2.3