ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109456] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
@ 2022-08-09 13:38 shioyama (Chris Salzberg)
  2022-08-09 13:44 ` [ruby-core:109457] " shioyama (Chris Salzberg)
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-08-09 13:38 UTC (permalink / raw)
  To: ruby-core

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

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

* Author: shioyama (Chris Salzberg)
* Status: Open
* Priority: Normal
* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:109457] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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 ` shioyama (Chris Salzberg)
  2022-08-22  4:30 ` [ruby-core:109623] " shioyama (Chris Salzberg)
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-08-09 13:44 UTC (permalink / raw)
  To: ruby-core

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


Pull Request: https://github.com/ruby/ruby/pull/6226

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:109623] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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 ` shioyama (Chris Salzberg)
  2022-08-22  5:02 ` [ruby-core:109624] " jeremyevans0 (Jeremy Evans)
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-08-22  4:30 UTC (permalink / raw)
  To: ruby-core

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


I'm new to contributing to Ruby, but I haven't gotten a response on this in a couple weeks so wondering if maybe this requires more context.

For reference, here are the docs on the `wrap` parameter to [`Kernel#load`](https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-load):

> If the optional _wrap_ parameter is true, the loaded script will be executed under an anonymous module, protecting the calling program's global namespace. If the optional _wrap_ parameter is a module, the loaded script will be executed under the given module. In no circumstance will any local variables in the loaded file be propagated to the loading environment.

So in theory if I have a file like this:

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

then loading it with `wrap` in the following:

```ruby
MyModule = Module.new

load "./using.rb", MyModule
```

should be the same as this:

```ruby
module MyModule
  using Module.new
end
```

However, whereas the latter works fine, the former fails with the error reported in the issue.

Note that if I do the same inside of a block to `Module.new`, like this:

```ruby
Module.new do
  using Module.new
end
```

then I get a different error, `RuntimeError: Module#using is not permitted in methods`. So "the loaded script will be executed under an anonymous module" in the docs is somewhat misleading since it's not as simple as injecting the code in `using.rb` into the block to `Module.new`.

Regardless though I don't think the error I'm seeing ("main.using is permitted only at toplevel") is correct, I think this should work.

@jeremyevans0 You [most recently contributed to the `wrap` option](https://bugs.ruby-lang.org/issues/6210), what do you think about this? Would you see it as a bug?

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:109624] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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 ` jeremyevans0 (Jeremy Evans)
  2022-08-22  6:19 ` [ruby-core:109625] " shugo (Shugo Maeda)
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-08-22  5:02 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by jeremyevans0 (Jeremy Evans).


shioyama (Chris Salzberg) wrote in #note-3:
> @jeremyevans0 You [most recently contributed to the `wrap` option](https://bugs.ruby-lang.org/issues/6210), what do you think about this? Am I correct to consider this a bug, and [this](https://github.com/ruby/ruby/pull/6226) the correct fix?

I'm not sure whether this is a bug, but since `using` is permitted at top-;evel and also permitted in a module definition, it seems logical it should work at top-level with an implicit top-level module.  The pull request looks correct to me.  Not sure if the spec should use `ruby_bug`, I would just use `ruby_version_is`.

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:109625] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (2 preceding siblings ...)
  2022-08-22  5:02 ` [ruby-core:109624] " jeremyevans0 (Jeremy Evans)
@ 2022-08-22  6:19 ` shugo (Shugo Maeda)
  2022-08-22  7:48 ` [ruby-core:109626] " shioyama (Chris Salzberg)
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shugo (Shugo Maeda) @ 2022-08-22  6:19 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by shugo (Shugo Maeda).


shioyama (Chris Salzberg) wrote in #note-3:
> @jeremyevans0 You [most recently contributed to the `wrap` option](https://bugs.ruby-lang.org/issues/6210), what do you think about this? Am I correct to consider this a bug, and [this](https://github.com/ruby/ruby/pull/6226) the correct fix?

main.using should not be called in a method definition even if it's a wrapped script.
With your fix, the following script causes BUG:

```
excelsior:ruby$ cat using_in_method.rb
# using.rb
def foo
  using Module.new
end

foo
excelsior:ruby$ cat t.rb
load "./using_in_method.rb", true
excelsior:ruby$ ./miniruby t.rb
/Users/shugo/src/ruby/using_in_method.rb:3: [BUG] vm_cref_dup: unreachable
ruby 3.2.0dev (2022-08-22T06:05:24Z shioyama-using_in_.. 08bdfcde78) [x86_64-darwin21]
```

I'm not sure whether this issue should be considered a bug, but it may be safe not to backport the fix to stable versions.




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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:109626] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (3 preceding siblings ...)
  2022-08-22  6:19 ` [ruby-core:109625] " shugo (Shugo Maeda)
@ 2022-08-22  7:48 ` shioyama (Chris Salzberg)
  2022-09-22 22:39 ` [ruby-core:110010] " mame (Yusuke Endoh)
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-08-22  7:48 UTC (permalink / raw)
  To: ruby-core

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


@jeremyevans0

> I'm not sure whether this issue should be considered a bug, but it may be safe not to backport the fix to stable versions.

Yes, that's what I had originally, in review I changed it to `ruby_bug`. Happy to put it back.

@shugo Ah ok now I see the purpose of that error, thanks.

> I'm not sure whether this issue should be considered a bug, but it may be safe not to backport the fix to stable versions.

Sure that makes sense.

It seems like we have two things (1- not allowing main.using to be called in a method definition, and 2- evaluating code in a wrapped script as if it were namespaced in a module) that are mutually incompatible in this case.

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110010] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (4 preceding siblings ...)
  2022-08-22  7:48 ` [ruby-core:109626] " shioyama (Chris Salzberg)
@ 2022-09-22 22:39 ` mame (Yusuke Endoh)
  2022-09-22 23:41 ` [ruby-core:110017] " shioyama (Chris Salzberg)
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mame (Yusuke Endoh) @ 2022-09-22 22:39 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by mame (Yusuke Endoh).


We discussed this issue at the dev meeting. No one objected to correcting this behavior, but the proposed PR is unacceptable because it causes [BUG] as @shugo said. Could you investigate the issue and update the PR?

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110017] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (5 preceding siblings ...)
  2022-09-22 22:39 ` [ruby-core:110010] " mame (Yusuke Endoh)
@ 2022-09-22 23:41 ` shioyama (Chris Salzberg)
  2022-09-22 23:55 ` [ruby-core:110019] " shugo (Shugo Maeda)
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-09-22 23:41 UTC (permalink / raw)
  To: ruby-core

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


Thanks! I'll do that and update here once the PR is again ready for review.

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110019] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (6 preceding siblings ...)
  2022-09-22 23:41 ` [ruby-core:110017] " shioyama (Chris Salzberg)
@ 2022-09-22 23:55 ` shugo (Shugo Maeda)
  2022-09-23  1:25 ` [ruby-core:110021] " shioyama (Chris Salzberg)
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shugo (Shugo Maeda) @ 2022-09-22 23:55 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by shugo (Shugo Maeda).


I guess SEGV is caused by `using` in a method body, which should be prohibited even in a wrapped script.

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110021] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (7 preceding siblings ...)
  2022-09-22 23:55 ` [ruby-core:110019] " shugo (Shugo Maeda)
@ 2022-09-23  1:25 ` shioyama (Chris Salzberg)
  2022-09-23  1:30 ` [ruby-core:110022] " shioyama (Chris Salzberg)
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-09-23  1:25 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110022] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (8 preceding siblings ...)
  2022-09-23  1:25 ` [ruby-core:110021] " shioyama (Chris Salzberg)
@ 2022-09-23  1:30 ` shioyama (Chris Salzberg)
  2022-09-23  1:36 ` [ruby-core:110023] " shioyama (Chris Salzberg)
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-09-23  1:30 UTC (permalink / raw)
  To: ruby-core

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


@shugo

Actually, it seems the same problem _is_ there with `require`:


```ruby
# foo.rb
def foo
  using Module.new
end

foo
```

```ruby
require "foo"
# main.using is permitted only at toplevel (RuntimeError)
```

So I don't really understand why Ruby allows the usage of `using` at toplevel with `require`, but not with `load`. Isn't this a problem in both cases?

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110023] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (9 preceding siblings ...)
  2022-09-23  1:30 ` [ruby-core:110022] " shioyama (Chris Salzberg)
@ 2022-09-23  1:36 ` shioyama (Chris Salzberg)
  2022-09-23  2:51 ` [ruby-core:110026] " shugo (Shugo Maeda)
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-09-23  1:36 UTC (permalink / raw)
  To: ruby-core

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


Oh never mind, I see. My PR results in the error with `require` but the `unreachable` BUG with `load`.

Ok I'll try to find another way to fix it.

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110026] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (10 preceding siblings ...)
  2022-09-23  1:36 ` [ruby-core:110023] " shioyama (Chris Salzberg)
@ 2022-09-23  2:51 ` 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)
  13 siblings, 0 replies; 15+ messages in thread
From: shugo (Shugo Maeda) @ 2022-09-23  2:51 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by shugo (Shugo Maeda).


shioyama (Chris Salzberg) wrote in #note-12:
> Oh never mind, I see. My PR results in the error with `require` but the `unreachable` BUG with `load`.
> 
> Ok I'll try to find another way to fix it.

Yes, RuntimeError should be raised in both cases.


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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110031] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (11 preceding siblings ...)
  2022-09-23  2:51 ` [ruby-core:110026] " shugo (Shugo Maeda)
@ 2022-09-23  5:58 ` shioyama (Chris Salzberg)
  2022-09-23 10:28 ` [ruby-core:110043] " shugo (Shugo Maeda)
  13 siblings, 0 replies; 15+ messages in thread
From: shioyama (Chris Salzberg) @ 2022-09-23  5:58 UTC (permalink / raw)
  To: ruby-core

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


@shugo I've updated my PR and added a spec calling a method which calls `using`, which fails with the previous code but passes with the updated code. Can you have a look?

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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:110043] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script
  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)
                   ` (12 preceding siblings ...)
  2022-09-23  5:58 ` [ruby-core:110031] " shioyama (Chris Salzberg)
@ 2022-09-23 10:28 ` shugo (Shugo Maeda)
  13 siblings, 0 replies; 15+ messages in thread
From: shugo (Shugo Maeda) @ 2022-09-23 10:28 UTC (permalink / raw)
  To: ruby-core

Issue #18960 has been updated by shugo (Shugo Maeda).


shioyama (Chris Salzberg) wrote in #note-14:
> @shugo I've updated [my PR](https://github.com/ruby/ruby/pull/6226) and added a spec calling a method which calls `using`, which fails with the previous code but passes with the updated code. Can you have a look?

Thank you!

I found another corner case.  The following code should be prohibited in a wrapped script:

```
MAIN = self

module X
  MAIN.send(:using, Module.new)
end
```

I suggested changes in the following comment:

https://github.com/ruby/ruby/pull/6226#pullrequestreview-1118228759


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

* 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/

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-09-23 10:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:110021] " shioyama (Chris Salzberg)
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)

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).