Skip to content

Commit 13eaf68

Browse files
committed
Remove explicit cloning of exception messages from core files.
Semantically, these messages shouldn't be frozen. In practice, it's very unlikely someone will try to mutate an exception's message. In order to clean up the source code, the explicit `+` calls are removed. If this turns out to be problematic, we can look at implicitly adding them back in when building the AST.
1 parent b9adc4a commit 13eaf68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+255
-255
lines changed

src/main/ruby/core/argf.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def eof?
213213
# multiple FDs and if so, is this correct? --rue
214214
#
215215
def fileno
216-
raise ArgumentError, +'No stream' unless advance!
216+
raise ArgumentError, 'No stream' unless advance!
217217
@stream.fileno
218218
end
219219
alias_method :to_i, :fileno
@@ -327,7 +327,7 @@ def lineno=(val)
327327
# @see IO#pos.
328328
#
329329
def pos
330-
raise ArgumentError, +'no stream' unless advance!
330+
raise ArgumentError, 'no stream' unless advance!
331331
@stream.tell
332332
end
333333
alias_method :tell, :pos
@@ -338,7 +338,7 @@ def pos
338338
# @see IO#pos=
339339
#
340340
def pos=(position)
341-
raise ArgumentError, +'no stream' unless advance!
341+
raise ArgumentError, 'no stream' unless advance!
342342
@stream.pos = position
343343
end
344344

@@ -357,7 +357,7 @@ def readbyte
357357
return val
358358
end
359359

360-
raise EOFError, +'ARGF at end'
360+
raise EOFError, 'ARGF at end'
361361
end
362362
alias_method :readchar, :readbyte
363363

@@ -469,13 +469,13 @@ def read_nonblock(bytes, output=nil, exception: true)
469469
# @see #gets
470470
#
471471
def readline(sep=$/)
472-
raise EOFError, +'ARGF at end' unless advance!
472+
raise EOFError, 'ARGF at end' unless advance!
473473

474474
if line = gets(sep)
475475
return line
476476
end
477477

478-
raise EOFError, +'ARGF at end'
478+
raise EOFError, 'ARGF at end'
479479
end
480480

481481
#
@@ -507,7 +507,7 @@ def readlines(sep=$/)
507507
# @todo Is this correct, only current stream is rewound? --rue
508508
#
509509
def rewind
510-
raise ArgumentError, +'no stream to rewind' unless advance!
510+
raise ArgumentError, 'no stream to rewind' unless advance!
511511
@lineno -= @stream.lineno
512512
@stream.rewind
513513
end
@@ -518,7 +518,7 @@ def rewind
518518
# @see IO#seek.
519519
#
520520
def seek(*args)
521-
raise ArgumentError, +'no stream' unless advance!
521+
raise ArgumentError, 'no stream' unless advance!
522522
@stream.seek(*args)
523523
end
524524

src/main/ruby/core/array.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def bsearch_index
261261
when false, nil
262262
min = i + 1
263263
else
264-
raise TypeError, +'wrong argument type (must be numeric, true, false or nil)'
264+
raise TypeError, 'wrong argument type (must be numeric, true, false or nil)'
265265
end
266266

267267
i = min + (max - min) / 2
@@ -426,13 +426,13 @@ def fetch(idx, default=undefined)
426426

427427
if block_given?
428428
unless undefined.equal?(c)
429-
raise ArgumentError, +'wrong number of arguments'
429+
raise ArgumentError, 'wrong number of arguments'
430430
end
431431
one = a
432432
two = b
433433
else
434434
if undefined.equal?(a)
435-
raise ArgumentError, +'wrong number of arguments'
435+
raise ArgumentError, 'wrong number of arguments'
436436
end
437437
obj = a
438438
one = b
@@ -443,7 +443,7 @@ def fetch(idx, default=undefined)
443443
left = 0
444444
right = size
445445
elsif one.kind_of? Range
446-
raise TypeError, +'length invalid with range' unless undefined.equal?(two)
446+
raise TypeError, 'length invalid with range' unless undefined.equal?(two)
447447

448448
left = Truffle::Type.coerce_to_collection_length one.begin
449449
left += size if left < 0
@@ -463,9 +463,9 @@ def fetch(idx, default=undefined)
463463
begin
464464
right = Truffle::Type.coerce_to_collection_length two
465465
rescue ArgumentError
466-
raise RangeError, +'bignum too big to convert into `long'
466+
raise RangeError, 'bignum too big to convert into `long'
467467
rescue TypeError
468-
raise ArgumentError, +'second argument must be an Integer'
468+
raise ArgumentError, 'second argument must be an Integer'
469469
end
470470

471471
return self if right == 0
@@ -476,7 +476,7 @@ def fetch(idx, default=undefined)
476476
end
477477

478478
unless Truffle::Type.fits_into_long?(left) && Truffle::Type.fits_into_long?(right)
479-
raise ArgumentError, +'argument too big'
479+
raise ArgumentError, 'argument too big'
480480
end
481481

482482
i = left
@@ -499,7 +499,7 @@ def first(n = undefined)
499499
return at(0) if undefined.equal?(n)
500500

501501
n = Truffle::Type.coerce_to_collection_index(n)
502-
raise ArgumentError, +'Size must be positive' if n < 0
502+
raise ArgumentError, 'Size must be positive' if n < 0
503503

504504
Array.new self[0, n]
505505
end
@@ -629,7 +629,7 @@ def join(sep=nil)
629629
return ''.encode(Encoding::US_ASCII) if size == 0
630630

631631
out = +''
632-
raise ArgumentError, +'recursive array join' if Thread.detect_recursion self do
632+
raise ArgumentError, 'recursive array join' if Thread.detect_recursion self do
633633
sep = sep.nil? ? $, : StringValue(sep)
634634

635635
# We've manually unwound the first loop entry for performance
@@ -689,7 +689,7 @@ def last(n=undefined)
689689
n = Truffle::Type.coerce_to_collection_index n
690690
return [] if n == 0
691691

692-
raise ArgumentError, +'count must be positive' if n < 0
692+
raise ArgumentError, 'count must be positive' if n < 0
693693

694694
n = size if n > size
695695
Array.new self[-n..-1]
@@ -793,7 +793,7 @@ def product(*args)
793793
sum = args.inject(size) { |n, x| n * x.size }
794794

795795
unless Truffle.invoke_primitive(:integer_fits_into_long, sum)
796-
raise RangeError, +'product result is too large'
796+
raise RangeError, 'product result is too large'
797797
end
798798

799799
# TODO rewrite this to not use a tree of Proc objects.
@@ -991,8 +991,8 @@ def initialize(rng)
991991

992992
def rand(size)
993993
random = Truffle::Type.coerce_to_collection_index @rng.rand(size)
994-
raise RangeError, +'random value must be >= 0' if random < 0
995-
raise RangeError, +'random value must be less than Array size' unless random < size
994+
raise RangeError, 'random value must be >= 0' if random < 0
995+
raise RangeError, 'random value must be less than Array size' unless random < size
996996

997997
random
998998
end
@@ -1015,7 +1015,7 @@ def sample(count=undefined, options=undefined)
10151015
end
10161016

10171017
if count and count < 0
1018-
raise ArgumentError, +'count must be greater than 0'
1018+
raise ArgumentError, 'count must be greater than 0'
10191019
end
10201020

10211021
rng = options[:random] if options
@@ -1140,7 +1140,7 @@ def shuffle!(options = undefined)
11401140

11411141
def drop(n)
11421142
n = Truffle::Type.coerce_to_collection_index n
1143-
raise ArgumentError, +'attempt to drop negative size' if n < 0
1143+
raise ArgumentError, 'attempt to drop negative size' if n < 0
11441144

11451145
new_size = size - n
11461146
return [] if new_size <= 0
@@ -1183,7 +1183,7 @@ def transpose
11831183
max ||= ary.size
11841184

11851185
# Catches too-large as well as too-small (for which #fetch would suffice)
1186-
raise IndexError, +'All arrays must be same length' if ary.size != max
1186+
raise IndexError, 'All arrays must be same length' if ary.size != max
11871187

11881188
ary.size.times do |i|
11891189
entry = (out[i] ||= [])
@@ -1307,7 +1307,7 @@ def recursively_flatten(array, out, max_levels = -1)
13071307
end
13081308
end
13091309

1310-
raise ArgumentError, +'tried to flatten recursive array' if recursion
1310+
raise ArgumentError, 'tried to flatten recursive array' if recursion
13111311
modified
13121312
end
13131313
private :recursively_flatten
@@ -1504,7 +1504,7 @@ def isort_block!(left, right, block)
15041504
block_result = block.call(el1, el2)
15051505

15061506
if block_result.nil?
1507-
raise ArgumentError, +'block returned nil'
1507+
raise ArgumentError, 'block returned nil'
15081508
elsif block_result > 0
15091509
self[j] = el1
15101510
self[j - 1] = el2

src/main/ruby/core/complex.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Complex < Numeric
5858

5959
def self.convert(real, imag = undefined)
6060
if nil.equal?(real) || nil.equal?(imag)
61-
raise TypeError, +'cannot convert nil into Complex'
61+
raise TypeError, 'cannot convert nil into Complex'
6262
end
6363
imag = nil if undefined.equal?(imag)
6464

@@ -105,13 +105,13 @@ def Complex.generic?(other) # :nodoc:
105105
end
106106

107107
def Complex.rect(real, imag=0)
108-
raise TypeError, +'not a real' unless check_real?(real) && check_real?(imag)
108+
raise TypeError, 'not a real' unless check_real?(real) && check_real?(imag)
109109
new(real, imag)
110110
end
111111
class << self; alias_method :rectangular, :rect end
112112

113113
def Complex.polar(r, theta=0)
114-
raise TypeError, +'not a real' unless check_real?(r) && check_real?(theta)
114+
raise TypeError, 'not a real' unless check_real?(r) && check_real?(theta)
115115

116116
Complex(r*Math.cos(theta), r*Math.sin(theta))
117117
end

src/main/ruby/core/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def initialize
3535

3636
def get_variable(name)
3737
Truffle.primitive :vm_get_config_item
38-
raise PrimitiveFailure, +'Truffle::Configuration#get_variable primitive failed'
38+
raise PrimitiveFailure, 'Truffle::Configuration#get_variable primitive failed'
3939
end
4040

4141
def section(section, &block)

src/main/ruby/core/dir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def initialize(path, options=undefined)
5858
end
5959

6060
private def ensure_open
61-
raise IOError, +'closed directory' if closed?
61+
raise IOError, 'closed directory' if closed?
6262
end
6363

6464
def fileno

src/main/ruby/core/dir_glob.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def call(matches, start)
132132

133133
class StartRecursiveDirectories < Node
134134
def call(matches, start)
135-
raise(+'invalid usage') if start
135+
raise 'invalid usage' if start
136136

137137
# Even though the recursive entry is zero width
138138
# in this case, its left separator is still the

src/main/ruby/core/encoding.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class << self
120120
end
121121

122122
def self.default_external=(enc)
123-
raise ArgumentError, +'default external encoding cannot be nil' if enc.nil?
123+
raise ArgumentError, 'default external encoding cannot be nil' if enc.nil?
124124

125125
enc = find(enc)
126126
set_alias_index 'external', enc

src/main/ruby/core/enumerable.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
module Enumerable
3535
def chunk(&original_block)
3636
initial_state = nil
37-
raise ArgumentError, +'no block given' unless block_given?
37+
raise ArgumentError, 'no block given' unless block_given?
3838
Enumerator.new do |yielder|
3939
previous = nil
4040
accumulate = []
@@ -55,7 +55,7 @@ def chunk(&original_block)
5555
when :_alone
5656
yielder.yield [key, [val]]
5757
else
58-
raise RuntimeError, +'symbols beginning with an underscore are reserved'
58+
raise RuntimeError, 'symbols beginning with an underscore are reserved'
5959
end
6060
else
6161
if previous.nil? || previous == key
@@ -192,9 +192,9 @@ def group_by
192192
def slice_after(arg = undefined, &block)
193193
has_arg = !(undefined.equal? arg)
194194
if block_given?
195-
raise ArgumentError, +'both pattern and block are given' if has_arg
195+
raise ArgumentError, 'both pattern and block are given' if has_arg
196196
else
197-
raise ArgumentError, +'wrong number of arguments (0 for 1)' unless has_arg
197+
raise ArgumentError, 'wrong number of arguments (0 for 1)' unless has_arg
198198
block = Proc.new{ |elem| arg === elem }
199199
end
200200
Enumerator.new do |yielder|
@@ -219,10 +219,10 @@ def slice_before(arg = undefined, &block)
219219
if block_given?
220220
has_init = !(undefined.equal? arg)
221221
if has_init
222-
raise ArgumentError, +'both pattern and block are given'
222+
raise ArgumentError, 'both pattern and block are given'
223223
end
224224
else
225-
raise ArgumentError, +'wrong number of arguments (0 for 1)' if undefined.equal? arg
225+
raise ArgumentError, 'wrong number of arguments (0 for 1)' if undefined.equal? arg
226226
block = Proc.new{ |elem| arg === elem }
227227
end
228228
Enumerator.new do |yielder|
@@ -544,7 +544,7 @@ def cycle(many=nil)
544544

545545
def drop(n)
546546
n = Truffle::Type.coerce_to_collection_index n
547-
raise ArgumentError, +'attempt to drop negative size' if n < 0
547+
raise ArgumentError, 'attempt to drop negative size' if n < 0
548548

549549
ary = to_a
550550
return [] if n > ary.size
@@ -789,7 +789,7 @@ def min_by(n = nil, &block)
789789
def self.sort_proc
790790
@sort_proc ||= Proc.new do |a, b|
791791
unless ret = a <=> b
792-
raise ArgumentError, +'Improper spaceship value'
792+
raise ArgumentError, 'Improper spaceship value'
793793
end
794794
ret
795795
end
@@ -807,12 +807,12 @@ def minmax(&block)
807807
first_time = false
808808
else
809809
unless min_cmp = block.call(min, object)
810-
raise ArgumentError, +'comparison failed'
810+
raise ArgumentError, 'comparison failed'
811811
end
812812
min = object if min_cmp > 0
813813

814814
unless max_cmp = block.call(max, object)
815-
raise ArgumentError, +'comparison failed'
815+
raise ArgumentError, 'comparison failed'
816816
end
817817

818818
max = object if max_cmp < 0

0 commit comments

Comments
 (0)