From: "matz (Yukihiro Matsumoto) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "matz (Yukihiro Matsumoto)" <noreply@ruby-lang.org>
Subject: [ruby-core:120291] [Ruby master Bug#20943] Constant defined in `Data.define` block
Date: Wed, 18 Dec 2024 06:19:16 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-111056.20241218061916.4@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20943.20241211020608.4@ruby-lang.org>
Issue #20943 has been updated by matz (Yukihiro Matsumoto).
Blocks do not introduce new scope even with `instance_eval` nor `class_eval` (along with `Data.define` etc. with blocks). Changing this behavior might cause serious compatibility problems.
If someone is willing to survey and estimate how much influence it could cause, we'd like to discuss. Otherwise, it's safe to keep the behavior as it is.
Matz.
----------------------------------------
Bug #20943: Constant defined in `Data.define` block
https://bugs.ruby-lang.org/issues/20943#change-111056
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
>From https://github.com/ruby/ruby/pull/12274:
> A couple times in code review I've seen constants inadvertently leak to top level from within a `Struct` or `Data` do block. I think it would be nice to show reopening the `Data` class when a constant is defined, so the constant is defined within the namespace. In this case, `Measure::NONE` instead of top level `Object::NONE`. It would also show readers that it's okay to reopen a `Data` class, which seems nice since some folk might not realize. Thanks for considering!
However, I think that `NONE` probably might be intended to be defined under `Measure`.
Current:
```ruby
Measure = Data.define(:amount, :unit) do
NONE = Data.define
end
p NONE #=> NONE
```
Another:
```ruby
Measure = Data.define(:amount, :unit) do
NONE = Data.define
p NONE #=> Measure::NONE
end
p NONE # uninitialized constant NONE (NameError)
```
@zverok How do think?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
next prev parent reply other threads:[~2024-12-18 6:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 2:06 [ruby-core:120174] [Ruby master Bug#20943] Constant defined in `Data` block nobu (Nobuyoshi Nakada) via ruby-core
2024-12-11 10:29 ` [ruby-core:120176] [Ruby master Bug#20943] Constant defined in `Data.define` block byroot (Jean Boussier) via ruby-core
2024-12-11 18:56 ` [ruby-core:120182] " matheusrich (Matheus Richard) via ruby-core
2024-12-17 23:51 ` [ruby-core:120284] " shan (Shannon Skipper) via ruby-core
2024-12-18 6:19 ` matz (Yukihiro Matsumoto) via ruby-core [this message]
2024-12-18 7:58 ` [ruby-core:120293] " zverok (Victor Shepelev) via ruby-core
2024-12-24 20:16 ` [ruby-core:120400] " luke-gru (Luke Gruber) via ruby-core
2024-12-30 10:35 ` [ruby-core:120446] " byroot (Jean Boussier) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-111056.20241218061916.4@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).