mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
freeze all Range objects.
Matz want to try to freeze all Range objects. [Feature #15504]
This commit is contained in:
parent
f4328d7f5d
commit
0096d2b895
Notes:
git
2020-09-25 22:17:22 +09:00
7 changed files with 22 additions and 10 deletions
4
NEWS.md
4
NEWS.md
|
@ -163,6 +163,10 @@ Outstanding ones only.
|
|||
p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
|
||||
```
|
||||
|
||||
* Range
|
||||
|
||||
* All Range objects are frozen. [Feature #15504]
|
||||
|
||||
* Thread
|
||||
|
||||
* Introduce `Thread#scheduler` for intercepting blocking operations and
|
||||
|
|
|
@ -448,9 +448,9 @@ assert_equal "ok", %q{
|
|||
[{a: 1}.freeze, 'str'.freeze].freeze, # nested frozen container
|
||||
S.new(1, 2).freeze, # frozen Struct
|
||||
S.new(1, 2, 3, 4).freeze, # frozen Struct
|
||||
(1..2).freeze, # Range on Struct
|
||||
(1..).freeze, # Range on Strcut
|
||||
(..1).freeze, # Range on Strcut
|
||||
(1..2), # Range on Struct
|
||||
(1..), # Range on Strcut
|
||||
(..1), # Range on Strcut
|
||||
C, # class
|
||||
M, # module
|
||||
Ractor.current, # Ractor
|
||||
|
@ -463,7 +463,6 @@ assert_equal "ok", %q{
|
|||
S.new(1, 2),
|
||||
S.new(1, 2, 3, 4),
|
||||
S.new("a", 2).freeze, # frozen, but refers to an unshareable object
|
||||
(1..2), (1..), (..1),
|
||||
]
|
||||
|
||||
results = []
|
||||
|
|
4
range.c
4
range.c
|
@ -58,6 +58,10 @@ range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
|
|||
RANGE_SET_EXCL(range, exclude_end);
|
||||
RANGE_SET_BEG(range, beg);
|
||||
RANGE_SET_END(range, end);
|
||||
|
||||
if (CLASS_OF(range) == rb_cRange) {
|
||||
rb_obj_freeze(range);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
|
@ -419,7 +419,7 @@ describe "Marshal.dump" do
|
|||
load.should == range
|
||||
load.instance_variable_get(:@foo).should == 42
|
||||
end
|
||||
end
|
||||
end unless (1...3).frozen? # Ruby 3.0 -
|
||||
|
||||
describe "with a Time" do
|
||||
before :each do
|
||||
|
|
|
@ -28,8 +28,13 @@ describe "Range#initialize" do
|
|||
end
|
||||
|
||||
it "raises a NameError if called on an already initialized Range" do
|
||||
-> { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError)
|
||||
-> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError)
|
||||
if (0..1).frozen? # Ruby 3.0-
|
||||
-> { (0..1).send(:initialize, 1, 3) }.should raise_error(FrozenError)
|
||||
-> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(FrozenError)
|
||||
else
|
||||
-> { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError)
|
||||
-> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if arguments don't respond to <=>" do
|
||||
|
|
|
@ -2612,7 +2612,7 @@ class TestArray < Test::Unit::TestCase
|
|||
|
||||
def test_zip_bug
|
||||
bug8153 = "ruby-core:53650"
|
||||
r = 1..1
|
||||
r = [1]
|
||||
def r.respond_to?(*)
|
||||
super
|
||||
end
|
||||
|
|
|
@ -163,8 +163,8 @@ class TestRange < Test::Unit::TestCase
|
|||
|
||||
def test_initialize_twice
|
||||
r = eval("1..2")
|
||||
assert_raise(NameError) { r.instance_eval { initialize 3, 4 } }
|
||||
assert_raise(NameError) { r.instance_eval { initialize_copy 3..4 } }
|
||||
assert_raise(FrozenError) { r.instance_eval { initialize 3, 4 } }
|
||||
assert_raise(FrozenError) { r.instance_eval { initialize_copy 3..4 } }
|
||||
end
|
||||
|
||||
def test_uninitialized_range
|
||||
|
|
Loading…
Add table
Reference in a new issue