diff options
author | Jean Boussier <[email protected]> | 2024-01-16 09:33:16 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-03-13 09:39:09 +0100 |
commit | a5c5f83b24a1b7024d4e7fe3bbce091634da53b2 (patch) | |
tree | 934bf77f4320f75e5e72beaae89300b296f9306d /variable.c | |
parent | 0b7487b44ecc0f95dcc8bfa0fdf7d5915dcc0f8f (diff) |
Make `const_source_location` return the real constant as soon as defined
[Bug #20188]
Ref: https://github.com/fxn/zeitwerk/issues/281#issuecomment-1893228355
Previously, it would only return the real constant location once the
autoload was fully completed.
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/variable.c b/variable.c index b484d65d19..99332d89a0 100644 --- a/variable.c +++ b/variable.c @@ -3189,6 +3189,19 @@ rb_const_location_from(VALUE klass, ID id, int exclude, int recurse, int visibil if (exclude && klass == rb_cObject) { goto not_found; } + + if (UNDEF_P(ce->value)) { // autoload + VALUE autoload_const_value = autoload_data(klass, id); + if (RTEST(autoload_const_value)) { + struct autoload_const *autoload_const; + struct autoload_data *autoload_data = get_autoload_data(autoload_const_value, &autoload_const); + + if (!UNDEF_P(autoload_const->value) && RTEST(rb_mutex_owned_p(autoload_data->mutex))) { + return rb_assoc_new(autoload_const->file, INT2NUM(autoload_const->line)); + } + } + } + if (NIL_P(ce->file)) return rb_ary_new(); return rb_assoc_new(ce->file, INT2NUM(ce->line)); } |