Backport #8025

Module#included_modules includes classes

Added by Marc-Andre Lafortune about 1 year ago. Updated 12 months ago.

[ruby-core:53158]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

I see two problems in the following code:

module Mixin
end

class C
  prepend Mixin
end

C.included_modules # => [Mixin, C, Kernel]

1) C should definitely not be there, since no class should ever appear in that list.

2) I wonder if Mixin should be there, since it was prepended to C, not included.


Related issues

Related to ruby-trunk - Bug #8841: Module#included_modules and prepended modules Open 08/31/2013

Associated revisions

Revision 40627
Added by Tomoyuki Chikanaga 12 months ago

merge revision(s) 40612,40614: [Backport #8025]

* class.c (rb_mod_included_modules): should not include the original
  module itself.   [Bug #8025]

* class.c (rb_mod_included_modules): should not include non-modules.
   [Bug #8025]

History

#1 Updated by Nobuyoshi Nakada 12 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40612.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


class.c: exclude original module

  • class.c (rbmodincluded_modules): should not include the original module itself. [Bug #8025]

#2 Updated by Nobuyoshi Nakada 12 months ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from Yukihiro Matsumoto to Tomoyuki Chikanaga
  • Target version deleted (2.1.0)

#3 Updated by Tomoyuki Chikanaga 12 months ago

  • Assignee changed from Tomoyuki Chikanaga to Nobuyoshi Nakada

Hello,

A problem seems to remain in case of inherited Class was prepended by a Module.
See the following sample.

module M1; end

class C1
prepend M1
end

class C2 < C1
end

p C1.includedmodules # => [M1, Kernel]
p C2.included
modules # => [M1, C1, Kernel]

Thanks,

#4 Updated by Tomoyuki Chikanaga 12 months ago

  • Assignee changed from Nobuyoshi Nakada to Tomoyuki Chikanaga

r40614 is an additional commit. Thank you nobu.

#5 Updated by Tomoyuki Chikanaga 12 months ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40627.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40612,40614: [Backport #8025]

* class.c (rb_mod_included_modules): should not include the original
  module itself.   [Bug #8025]

* class.c (rb_mod_included_modules): should not include non-modules.
   [Bug #8025]

Also available in: Atom PDF