ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "shioyama (Chris Salzberg)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:110021] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
Date: Fri, 23 Sep 2022 01:25:40 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99272.20220923012539.13031@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18960.20220809133842.13031@ruby-lang.org

Issue #18960 has been updated by shioyama (Chris Salzberg).


Hmm, ok this is where the problem happens without the patch:

https://github.com/shioyama/rails/blob/b9493a47e65287f3b135904dbdd511bbf5a5798c/activesupport/lib/active_support/core_ext/enumerable.rb#L285-L291

```ruby
# Using Refinements here in order not to expose our internal method
using Module.new {
  refine Array do
    alias :orig_sum :sum
  end
}
```

Although this is somewhat contrived, you can reproduce the problem on the same file as follows:

```ruby
mod = Module.new
mod::Enumerable = Enumerable

load $LOAD_PATH.resolve_feature_path("active_support/core_ext/enumerable")[1], mod
# main.using is permitted only at toplevel (RuntimeError)
```

----------------------------------------
Bug #18960: Module#using raises RuntimeError when called at toplevel from wrapped script
https://bugs.ruby-lang.org/issues/18960#change-99272

* Author: shioyama (Chris Salzberg)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2p20
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I noticed that this file works when loaded with `load`, but fails if you pass `true` (or a module) as the `wrap` argument.

```ruby
# using.rb
using Module.new
```

This works:

```ruby
load "./using.rb"
```

This doesn't:
```ruby
load "./using.rb", true
# raises RuntimeError (main.using is permitted only at toplevel)
```

I believe the latter should work.



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2022-09-23  1:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 13:38 [ruby-core:109456] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script shioyama (Chris Salzberg)
2022-08-09 13:44 ` [ruby-core:109457] " shioyama (Chris Salzberg)
2022-08-22  4:30 ` [ruby-core:109623] " shioyama (Chris Salzberg)
2022-08-22  5:02 ` [ruby-core:109624] " jeremyevans0 (Jeremy Evans)
2022-08-22  6:19 ` [ruby-core:109625] " shugo (Shugo Maeda)
2022-08-22  7:48 ` [ruby-core:109626] " shioyama (Chris Salzberg)
2022-09-22 22:39 ` [ruby-core:110010] " mame (Yusuke Endoh)
2022-09-22 23:41 ` [ruby-core:110017] " shioyama (Chris Salzberg)
2022-09-22 23:55 ` [ruby-core:110019] " shugo (Shugo Maeda)
2022-09-23  1:25 ` shioyama (Chris Salzberg) [this message]
2022-09-23  1:30 ` [ruby-core:110022] " shioyama (Chris Salzberg)
2022-09-23  1:36 ` [ruby-core:110023] " shioyama (Chris Salzberg)
2022-09-23  2:51 ` [ruby-core:110026] " shugo (Shugo Maeda)
2022-09-23  5:58 ` [ruby-core:110031] " shioyama (Chris Salzberg)
2022-09-23 10:28 ` [ruby-core:110043] " shugo (Shugo Maeda)

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99272.20220923012539.13031@ruby-lang.org \
    --to=ruby-core@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 read-only IMAP folder(s) and NNTP newsgroup(s).