Project

General

Profile

Actions

Bug #11714

closed

`include Module` affects scope of code loaded by require statements on Ruby 2.2+

Added by terceiro (Antonio Terceiro) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-11-19 master 52671) [x86_64-linux]
[ruby-core:71583]

Description

This seems to be a regression with Ruby 2.2 and beyond, I can still reproduce this in Ruby trunk from today. Ruby 2.1 works just fine.

$ cat /tmp/test.rb 
module MyThing
  class Date < String
  end
end
include MyThing

require 'date'
$ ruby2.1 /tmp/test.rb 
$ ruby2.2 /tmp/test.rb 
/usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': superclass mismatch for class Date (TypeError)
	from /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /usr/lib/ruby/2.2.0/date.rb:3:in `<top (required)>'
	from /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /tmp/test.rb:7:in `<main>'
[1]$ /var/tmp/ruby-trunk/bin/ruby /tmp/test.rb
/var/tmp/ruby-trunk/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require': superclass mismatch for class Date (TypeError)
	from /var/tmp/ruby-trunk/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /var/tmp/ruby-trunk/lib/ruby/2.3.0/date.rb:3:in `<top (required)>'
	from /var/tmp/ruby-trunk/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /var/tmp/ruby-trunk/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /tmp/test.rb:7:in `<main>'

Updated by terceiro (Antonio Terceiro) over 8 years ago

  • Subject changed from `include Module` affects code scope of code loaded by require statements on Ruby 2.2+ to `include Module` affects scope of code loaded by require statements on Ruby 2.2+

Updated by shugo (Shugo Maeda) over 8 years ago

  • Status changed from Open to Rejected

Antonio Terceiro wrote:

This seems to be a regression with Ruby 2.2 and beyond, I can still reproduce this in Ruby trunk from today. Ruby 2.1 works just fine.

$ cat /tmp/test.rb 
module MyThing
  class Date < String
  end
end
include MyThing

require 'date'

It's not a regression.
Even in Ruby 2.1, include MyThing affects date.rb, but it doesn't affect Date because ::Date is defined by RubyGems before inclusion of MyThing.

You can see the same error in Ruby 2.1 by the option --disable=gems:

$ ruby --disable=gems test.rb

Without --disable=gems, you can see that Date is not affected by inclusion of MyThing even in test.rb:

module MyThing
  class Date < String
  end
end
include MyThing
p Date #=> Date, not MyThing::Date
Actions

Also available in: Atom PDF

Like0
Like0Like0