ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91333] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
@ 2019-01-30  7:19 ` ko1
  2019-01-30 12:17 ` [ruby-core:91339] " eregontp
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: ko1 @ 2019-01-30  7:19 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been reported by ko1 (Koichi Sasada).

----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91339] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
  2019-01-30  7:19 ` [ruby-core:91333] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class ko1
@ 2019-01-30 12:17 ` eregontp
  2019-01-30 12:24 ` [ruby-core:91341] " ko1
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: eregontp @ 2019-01-30 12:17 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by Eregon (Benoit Daloze).


Agreed.
IMHO `class << expr` should be no different than the normal `class Name`, but currently various things are allowed in that context such as `return`, `yield`, etc.

Constant resolution also becomes somewhat dynamically-scoped with `class << expr` which is also a weird exception.
So longer term maybe it would be good to deprecate `class <<` entirely and use `singleton_class.class_exec do` instead.

----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76588

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91341] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
  2019-01-30  7:19 ` [ruby-core:91333] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class ko1
  2019-01-30 12:17 ` [ruby-core:91339] " eregontp
@ 2019-01-30 12:24 ` ko1
  2019-01-30 12:27 ` [ruby-core:91343] " ko1
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: ko1 @ 2019-01-30 12:24 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by ko1 (Koichi Sasada).


Eregon (Benoit Daloze) wrote:
> Agreed.
> IMHO `class << expr` should be no different than the normal `class Name`, but currently various things are allowed in that context such as `return`, `yield`, etc.
> 
> Constant resolution also becomes somewhat dynamically-scoped with `class << expr` which is also a weird exception.
> So longer term maybe it would be good to deprecate `class <<` entirely and use `singleton_class.class_exec do` instead.

or make it syntax sugre of `singleton_class.class_exec do`?
Both are easy to explain the rule. Now, it is somewhat unclear.


----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76590

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91343] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-01-30 12:24 ` [ruby-core:91341] " ko1
@ 2019-01-30 12:27 ` ko1
  2019-01-30 12:28 ` [ruby-core:91344] " eregontp
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: ko1 @ 2019-01-30 12:27 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by ko1 (Koichi Sasada).


Similar strange example (off-topic):

```
1.times{
  class C
    break
    def undefined_method; end
  end
  p :unrechable
}
p [:ok, C.instance_methods(false)] #=> [:ok, []]
```

We can break from `class` syntax.
I hope nobody use it :(

----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76592

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91344] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-01-30 12:27 ` [ruby-core:91343] " ko1
@ 2019-01-30 12:28 ` eregontp
  2019-01-30 12:30 ` [ruby-core:91345] " eregontp
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: eregontp @ 2019-01-30 12:28 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by Eregon (Benoit Daloze).


ko1 (Koichi Sasada) wrote:
> or make it syntax sugre of `singleton_class.class_exec do`?

I think that would be confusing as `class` (like `module` and `def`) is a keyword which normally adds a new lexical scope and does not capture the parent local variables.


----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76593

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91345] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-01-30 12:28 ` [ruby-core:91344] " eregontp
@ 2019-01-30 12:30 ` eregontp
  2019-01-31  4:36 ` [ruby-core:91350] " alanwucanada
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: eregontp @ 2019-01-30 12:30 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by Eregon (Benoit Daloze).


ko1 (Koichi Sasada) wrote:
> We can break from `class` syntax.
> I hope nobody use it :(

At least TruffleRuby doesn't implement it, and we had no bug report about this, so hopefully not used.
Agreed it should be deprecated/removed as it's confusing at best.

----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76594

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91350] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-01-30 12:30 ` [ruby-core:91345] " eregontp
@ 2019-01-31  4:36 ` alanwucanada
  2019-01-31  8:02 ` [ruby-core:91352] " matz
  2019-02-04  6:43 ` [ruby-core:91390] " ko1
  8 siblings, 0 replies; 9+ messages in thread
From: alanwucanada @ 2019-01-31  4:36 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by alanwu (Alan Wu).


Another option would be to make everything use lexical scope, if the strangeness is indeed because locals are inaccessible inside class << self.
So imagine the following printing 1 2 3.
``` ruby
foo = 1
class A
  bar = 2
  def hi
    baz = 3
    class << self
      p foo, bar, baz
    end
  end
end
A.new.hi
```
Is it less strange if everything used the same scoping rule?



----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76602

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91352] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-01-31  4:36 ` [ruby-core:91350] " alanwucanada
@ 2019-01-31  8:02 ` matz
  2019-02-04  6:43 ` [ruby-core:91390] " ko1
  8 siblings, 0 replies; 9+ messages in thread
From: matz @ 2019-01-31  8:02 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by matz (Yukihiro Matsumoto).


Agreed to prohibit. Disagree to change the scoping rule (@alanwu).

Matz.


----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76604

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

* [ruby-core:91390] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class
       [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2019-01-31  8:02 ` [ruby-core:91352] " matz
@ 2019-02-04  6:43 ` ko1
  8 siblings, 0 replies; 9+ messages in thread
From: ko1 @ 2019-02-04  6:43 UTC (permalink / raw
  To: ruby-core

Issue #15575 has been updated by ko1 (Koichi Sasada).


Matz, Thank you for confirmation.

I add a warning (without -w) like that:

```ruby
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```
```
test.rb: warning: `yield' in class syntax will not be supported from Ruby 3.0. [Feature #15575]

```

English correction is wlecome :)


----------------------------------------
Feature #15575: Prohibit to pass a block singleton class
https://bugs.ruby-lang.org/issues/15575#change-76646

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The following code works now:

```
def foo
  class << Object.new
    yield
  end
end

foo{ p :ok } #=> :ok
```

but I think this feature is very strange because local variables are not active in singleton class.

How about to prohibit this feature?

plan: warning at ruby 2.7 and prohibit it in ruby 3.




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

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

end of thread, other threads:[~2019-02-04  6:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15575.20190130071922@ruby-lang.org>
2019-01-30  7:19 ` [ruby-core:91333] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class ko1
2019-01-30 12:17 ` [ruby-core:91339] " eregontp
2019-01-30 12:24 ` [ruby-core:91341] " ko1
2019-01-30 12:27 ` [ruby-core:91343] " ko1
2019-01-30 12:28 ` [ruby-core:91344] " eregontp
2019-01-30 12:30 ` [ruby-core:91345] " eregontp
2019-01-31  4:36 ` [ruby-core:91350] " alanwucanada
2019-01-31  8:02 ` [ruby-core:91352] " matz
2019-02-04  6:43 ` [ruby-core:91390] " ko1

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