diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2026-04-10 14:01:51 +0200 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2026-04-10 15:06:19 +0200 |
| commit | 7f4db64f28133c1b14d1714b113a26e82b65209a (patch) | |
| tree | 6e510acf6f38552e21bfd12f900899ba1db09370 | |
| parent | cfec60d4bec0d99e17ed56bea7055de7ec7674a1 (diff) | |
Emit already initialzed constant warnings in a single call
When decorating `Warning.warn`, it's much more convenient to get
the whole warning in a single string.
| -rw-r--r-- | variable.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/variable.c b/variable.c index 9df6e5911c..0eb10e6912 100644 --- a/variable.c +++ b/variable.c @@ -4002,15 +4002,17 @@ const_tbl_update(struct autoload_const *ac, int autoload_force) else { VALUE name = QUOTE_ID(id); visibility = ce->flag; - if (klass == rb_cObject) - rb_warn("already initialized constant %"PRIsVALUE"", name); - else - rb_warn("already initialized constant %"PRIsVALUE"::%"PRIsVALUE"", - rb_class_name(klass), name); + + VALUE previous = Qnil; if (!NIL_P(ce->file) && ce->line) { - rb_compile_warn(RSTRING_PTR(ce->file), ce->line, - "previous definition of %"PRIsVALUE" was here", name); + previous = rb_sprintf("\n%"PRIsVALUE":%d: warning: previous definition of %"PRIsVALUE" was here", ce->file, ce->line, name); } + + if (klass == rb_cObject) + rb_warn("already initialized constant %"PRIsVALUE"%"PRIsVALUE"", name, previous); + else + rb_warn("already initialized constant %"PRIsVALUE"::%"PRIsVALUE"%"PRIsVALUE"", + rb_class_name(klass), name, previous); } rb_clear_constant_cache_for_id(id); setup_const_entry(ce, klass, val, visibility); |
