ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:77610] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
@ 2016-10-13 10:48 ` ndnenkov
  2016-10-13 15:26 ` [ruby-core:77613] " zn
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: ndnenkov @ 2016-10-13 10:48 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been reported by Nikola Nenkov.

----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834

* Author: Nikola Nenkov
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:77613] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
  2016-10-13 10:48 ` [ruby-core:77610] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain ndnenkov
@ 2016-10-13 15:26 ` zn
  2016-10-13 15:42 ` [ruby-core:77614] " ndnenkov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: zn @ 2016-10-13 15:26 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by Kazuhiro NISHIYAMA.


`Module#include` can make multiple times module existence in `ancestors`.

```ruby
module M; end
class A; end
class B < A; include M; end
class A; include M; end
B.ancestors #=> [B, M, A, M, Object, Kernel, BasicObject]
```


----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-60881

* Author: Nikola Nenkov
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:77614] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
  2016-10-13 10:48 ` [ruby-core:77610] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain ndnenkov
  2016-10-13 15:26 ` [ruby-core:77613] " zn
@ 2016-10-13 15:42 ` ndnenkov
  2017-03-02  1:14 ` [ruby-core:79850] " samuel
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: ndnenkov @ 2016-10-13 15:42 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by Nikola Nenkov.


My point was that whether or not a module will get prepended can have an actual impact, yet it got changed between versions without an explicit notice. Given that the behaviour is documented as opposed to left undefined, I thought that this is a regression.

----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-60882

* Author: Nikola Nenkov
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:79850] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-10-13 15:42 ` [ruby-core:77614] " ndnenkov
@ 2017-03-02  1:14 ` samuel
  2017-04-18  4:54 ` [ruby-core:80757] " shyouhei
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: samuel @ 2017-03-02  1:14 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by Samuel Williams.


I feel like this is a bug, and should be fixed. Prepending the same thing multiple times should be a warning IMHO. I'm not even sure what situation this is useful.

```
2.4.0 :001 > module M
2.4.0 :002?>   end
 => nil 
2.4.0 :003 > module N
2.4.0 :004?>   end
 => nil 
2.4.0 :005 > class C
2.4.0 :006?>   prepend M, N, M
2.4.0 :007?>   end
 => C 
2.4.0 :008 > C.included_modules
 => [N, M, Kernel] 
2.4.0 :009 > D = C.dup.prepend(M)
 => D 
2.4.0 :010 > D.included_modules
 => [N, M, Kernel] 
2.4.0 :011 > class E < D
2.4.0 :012?>   prepend M
2.4.0 :013?>   end
 => E 
2.4.0 :014 > E.included_modules
 => [M, N, M, Kernel] 
2.4.0 :015 > 
```

----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-63283

* Author: Nikola Nenkov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:80757] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2017-03-02  1:14 ` [ruby-core:79850] " samuel
@ 2017-04-18  4:54 ` shyouhei
  2017-11-29 16:40 ` [ruby-core:83976] " ruby-core
  2017-11-30  0:53 ` [ruby-core:83989] " shyouhei
  6 siblings, 0 replies; 7+ messages in thread
From: shyouhei @ 2017-04-18  4:54 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by shyouhei (Shyouhei Urabe).


We looked at this issue in yesterday's developer meeting.

While discussing, we learned that prepended ancestors are not linearizable using the C3 algorithm.  When you prepend something, you normally want to override a method in a specific order.  So a prepending module and its prepended counterpart must be adjacent in a superclass resolution.  Thus, matz started thinking that if a module is prepended multiple times, that should appear more than once in a method chain.

----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-64313

* Author: ndn (Nikola Nenkov)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:83976] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2017-04-18  4:54 ` [ruby-core:80757] " shyouhei
@ 2017-11-29 16:40 ` ruby-core
  2017-11-30  0:53 ` [ruby-core:83989] " shyouhei
  6 siblings, 0 replies; 7+ messages in thread
From: ruby-core @ 2017-11-29 16:40 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by marcandre (Marc-Andre Lafortune).


shyouhei (Shyouhei Urabe) wrote:
> Thus, matz started thinking that if a module is prepended multiple times, that should appear more than once in a method chain.

Could you clarify?

For inclusion/prepending, there are two questions in my mind:
1) what happens if a module is included/prepended multiple times at different places in the hierarchy (e.g. in A and B, in the example above)
2) what happens if it is included/prepended multiple times at the same level (e.g. twice in A)

Was the discussion about (b) allowing multiple times at the same level?



----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-68056

* Author: ndn (Nikola Nenkov)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

* [ruby-core:83989] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain
       [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2017-11-29 16:40 ` [ruby-core:83976] " ruby-core
@ 2017-11-30  0:53 ` shyouhei
  6 siblings, 0 replies; 7+ messages in thread
From: shyouhei @ 2017-11-30  0:53 UTC (permalink / raw
  To: ruby-core

Issue #12834 has been updated by shyouhei (Shyouhei Urabe).


marcandre (Marc-Andre Lafortune) wrote:
> Could you clarify?
> 
> For inclusion/prepending, there are two questions in my mind:
> 1) what happens if a module is included/prepended multiple times at different places in the hierarchy (e.g. in A and B, in the example above)
> 2) what happens if it is included/prepended multiple times at the same level (e.g. twice in A)
> 
> Was the discussion about (b) allowing multiple times at the same level?

I don't remember there were discussions about inclusion in this topic.  There were ones for prepending only.  From what I understand the intention of prepending a module more than once is:

#### `1)`'s situation: ####

   ```ruby
module X              def x; "X<%s>" % super end end
module Y prepend ::X; def x; "Y<%s>" % super end end
module Z prepend ::Y; def x; "Z<%s>" % super end end
class W
  prepend ::X
  prepend ::Z
  def x
    'W'
  end
end
    
W.new.x # => "X<Y<Z<X<W>>>>"
   ```

#### `2)`'s situation: ####

   ```ruby
module X              def x; "X<%s>" % super end end
module Y prepend ::X; def x; "Y<%s>" % super end end
module Z prepend ::X; def x; "Z<%s>" % super end end
class W
  prepend ::Y
  prepend ::Z
  def x
    'W'
  end
end
    
W.new.x # => "X<Z<X<Y<W>>>>"
   ```

Note: current trunk does not behave this way.

----------------------------------------
Bug #12834: `prepend` getting prepended even if it already exists in the ancestors chain
https://bugs.ruby-lang.org/issues/12834#change-68068

* Author: ndn (Nikola Nenkov)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1
* Backport: 2.3: UNKNOWN
----------------------------------------
```
module M; end
class A; prepend M; end
class B < A; prepend M; end

B.ancestors # => [M, B, M, A, Object, Kernel, BasicObject]
```

Even though I find this behaviour to be more intuitive, it is inconsistent with `Module#include` and is potentially breaking.
I didn't see a mention on the [[release notes]](https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/) and the [[documentation]](https://ruby-doc.org/core-2.3.1/Module.html#method-i-prepend_features) is now outdated. 



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

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

end of thread, other threads:[~2017-11-30  0:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-12834.20161013104832@ruby-lang.org>
2016-10-13 10:48 ` [ruby-core:77610] [Ruby trunk Bug#12834] `prepend` getting prepended even if it already exists in the ancestors chain ndnenkov
2016-10-13 15:26 ` [ruby-core:77613] " zn
2016-10-13 15:42 ` [ruby-core:77614] " ndnenkov
2017-03-02  1:14 ` [ruby-core:79850] " samuel
2017-04-18  4:54 ` [ruby-core:80757] " shyouhei
2017-11-29 16:40 ` [ruby-core:83976] " ruby-core
2017-11-30  0:53 ` [ruby-core:83989] " shyouhei

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