aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 03:03:37 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-13 03:03:37 +0000
commit9d258137458ddabeeeb99882022b4da5c54e645c (patch)
treea865e953d2ba4a93e946167c479ca6b9c6043691
parent182f8d7e2750dfa6d7df8469a41c87c66eb0bd87 (diff)
downloadruby-9d258137458ddabeeeb99882022b4da5c54e645c.tar.gz
* test/ruby/test_basicinstructions.rb: add a test to check access
instance variables on special const objects. All of such objects are frozen, so that we can not set instance variables for them. But we can read instance variables and return default value (nil). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--test/ruby/test_basicinstructions.rb22
2 files changed, 31 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f39aeed38..995c9eb60a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Apr 13 12:00:08 2016 Koichi Sasada <ko1@atdot.net>
+
+ * test/ruby/test_basicinstructions.rb: add a test to check access
+ instance variables on special const objects.
+
+ All of such objects are frozen, so that we can not set instance
+ variables for them. But we can read instance variables and return
+ default value (nil).
+
Tue Apr 12 20:40:35 2016 Kaneko Yuichiro <spiketeika@gmail.com>
* ext/date/date_core.c (time_to_time): should preserve timezone
diff --git a/test/ruby/test_basicinstructions.rb b/test/ruby/test_basicinstructions.rb
index d13c41c276..c0ce02648d 100644
--- a/test/ruby/test_basicinstructions.rb
+++ b/test/ruby/test_basicinstructions.rb
@@ -698,4 +698,26 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_equal [], [*a]
assert_equal [1], [1, *a]
end
+
+ def test_special_const_instance_variables
+ assert_separately(%w(-W0), <<-INPUT, timeout: 60)
+ module M
+ def get
+ # we can not set instance variables on special const objects.
+ # However, we can access instance variables with default value (nil).
+ @ivar
+ end
+ end
+ class Fixnum; include M; end
+ class Float; include M; end
+ class Symbol; include M; end
+ class FalseClass; include M; end
+ class TrueClass; include M; end
+ class NilClass; include M; end
+
+ [123, 1.2, :sym, false, true, nil].each{|obj|
+ assert_equal(nil, obj.get)
+ }
+ INPUT
+ end
end