diff options
author | Dylan Thacker-Smith <Dylan.Smith@shopify.com> | 2019-11-06 01:47:32 -0500 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-13 15:36:58 +0900 |
commit | ac112f2b5dc7e16ccde8f048be80946187a033b0 (patch) | |
tree | 5ad84ea663becd04e7a77fd6f6cf5f4ea3678a86 /iseq.c | |
parent | a5b6d7bca84fce6e13c68e8753893c4697960e3a (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2657
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -1830,13 +1830,20 @@ rb_insn_operand_intern(const rb_iseq_t *iseq, case TS_NUM: /* ULONG */ if (insn == BIN(defined) && op_no == 0) { enum defined_type deftype = (enum defined_type)op; - if (deftype == DEFINED_FUNC) { - ret = rb_fstring_lit("func"); break; - } - if (deftype == DEFINED_REF) { - ret = rb_fstring_lit("ref"); break; + switch (deftype) { + case DEFINED_FUNC: + ret = rb_fstring_lit("func"); + break; + case DEFINED_REF: + ret = rb_fstring_lit("ref"); + break; + case DEFINED_CONST_FROM: + ret = rb_fstring_lit("constant-from"); + break; + default: + ret = rb_iseq_defined_string(deftype); + break; } - ret = rb_iseq_defined_string(deftype); if (ret) break; } else if (insn == BIN(checktype) && op_no == 0) { |