Skip to content

Commit 5da1405

Browse files
committed
Update core files to use frozen String literals.
1 parent 0d3f60d commit 5da1405

Some content is hidden

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

48 files changed

+395
-300
lines changed

src/main/ruby/core/argf.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -211,7 +213,7 @@ def eof?
211213
# multiple FDs and if so, is this correct? --rue
212214
#
213215
def fileno
214-
raise ArgumentError, 'No stream' unless advance!
216+
raise ArgumentError, +'No stream' unless advance!
215217
@stream.fileno
216218
end
217219
alias_method :to_i, :fileno
@@ -325,7 +327,7 @@ def lineno=(val)
325327
# @see IO#pos.
326328
#
327329
def pos
328-
raise ArgumentError, 'no stream' unless advance!
330+
raise ArgumentError, +'no stream' unless advance!
329331
@stream.tell
330332
end
331333
alias_method :tell, :pos
@@ -336,7 +338,7 @@ def pos
336338
# @see IO#pos=
337339
#
338340
def pos=(position)
339-
raise ArgumentError, 'no stream' unless advance!
341+
raise ArgumentError, +'no stream' unless advance!
340342
@stream.pos = position
341343
end
342344

@@ -355,7 +357,7 @@ def readbyte
355357
return val
356358
end
357359

358-
raise EOFError, 'ARGF at end'
360+
raise EOFError, +'ARGF at end'
359361
end
360362
alias_method :readchar, :readbyte
361363

@@ -467,13 +469,13 @@ def read_nonblock(bytes, output=nil, exception: true)
467469
# @see #gets
468470
#
469471
def readline(sep=$/)
470-
raise EOFError, 'ARGF at end' unless advance!
472+
raise EOFError, +'ARGF at end' unless advance!
471473

472474
if line = gets(sep)
473475
return line
474476
end
475477

476-
raise EOFError, 'ARGF at end'
478+
raise EOFError, +'ARGF at end'
477479
end
478480

479481
#
@@ -505,7 +507,7 @@ def readlines(sep=$/)
505507
# @todo Is this correct, only current stream is rewound? --rue
506508
#
507509
def rewind
508-
raise ArgumentError, 'no stream to rewind' unless advance!
510+
raise ArgumentError, +'no stream to rewind' unless advance!
509511
@lineno -= @stream.lineno
510512
@stream.rewind
511513
end
@@ -516,7 +518,7 @@ def rewind
516518
# @see IO#seek.
517519
#
518520
def seek(*args)
519-
raise ArgumentError, 'no stream' unless advance!
521+
raise ArgumentError, +'no stream' unless advance!
520522
@stream.seek(*args)
521523
end
522524

@@ -568,7 +570,7 @@ def to_io
568570
# Returns "ARGF" as the string representation of this object.
569571
#
570572
def to_s
571-
'ARGF'
573+
+'ARGF'
572574
end
573575

574576

@@ -592,7 +594,7 @@ def advance!
592594
if @argv.empty?
593595
@advance = false
594596
@stream = $stdin
595-
@filename = '-'
597+
@filename = +'-'
596598
@use_stdin_only = true
597599
return true
598600
end

src/main/ruby/core/array.rb

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -259,7 +261,7 @@ def bsearch_index
259261
when false, nil
260262
min = i + 1
261263
else
262-
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)'
263265
end
264266

265267
i = min + (max - min) / 2
@@ -424,13 +426,13 @@ def fetch(idx, default=undefined)
424426

425427
if block_given?
426428
unless undefined.equal?(c)
427-
raise ArgumentError, 'wrong number of arguments'
429+
raise ArgumentError, +'wrong number of arguments'
428430
end
429431
one = a
430432
two = b
431433
else
432434
if undefined.equal?(a)
433-
raise ArgumentError, 'wrong number of arguments'
435+
raise ArgumentError, +'wrong number of arguments'
434436
end
435437
obj = a
436438
one = b
@@ -441,7 +443,7 @@ def fetch(idx, default=undefined)
441443
left = 0
442444
right = size
443445
elsif one.kind_of? Range
444-
raise TypeError, 'length invalid with range' unless undefined.equal?(two)
446+
raise TypeError, +'length invalid with range' unless undefined.equal?(two)
445447

446448
left = Truffle::Type.coerce_to_collection_length one.begin
447449
left += size if left < 0
@@ -461,9 +463,9 @@ def fetch(idx, default=undefined)
461463
begin
462464
right = Truffle::Type.coerce_to_collection_length two
463465
rescue ArgumentError
464-
raise RangeError, 'bignum too big to convert into `long'
466+
raise RangeError, +'bignum too big to convert into `long'
465467
rescue TypeError
466-
raise ArgumentError, 'second argument must be an Integer'
468+
raise ArgumentError, +'second argument must be an Integer'
467469
end
468470

469471
return self if right == 0
@@ -474,7 +476,7 @@ def fetch(idx, default=undefined)
474476
end
475477

476478
unless Truffle::Type.fits_into_long?(left) && Truffle::Type.fits_into_long?(right)
477-
raise ArgumentError, 'argument too big'
479+
raise ArgumentError, +'argument too big'
478480
end
479481

480482
i = left
@@ -497,7 +499,7 @@ def first(n = undefined)
497499
return at(0) if undefined.equal?(n)
498500

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

502504
Array.new self[0, n]
503505
end
@@ -604,11 +606,11 @@ def insert(idx, *items)
604606
Truffle::Graal.always_split instance_method(:insert)
605607

606608
def inspect
607-
return '[]'.force_encoding(Encoding::US_ASCII) if size == 0
609+
return '[]'.encode(Encoding::US_ASCII) if size == 0
608610
comma = ', '
609-
result = '['
611+
result = +'['
610612

611-
return '[...]' if Thread.detect_recursion self do
613+
return +'[...]' if Thread.detect_recursion self do
612614
each_with_index do |element, index|
613615
temp = Truffle::Type.rb_inspect(element)
614616
result.force_encoding(temp.encoding) if index == 0
@@ -624,10 +626,10 @@ def inspect
624626
alias_method :to_s, :inspect
625627

626628
def join(sep=nil)
627-
return ''.force_encoding(Encoding::US_ASCII) if size == 0
629+
return ''.encode(Encoding::US_ASCII) if size == 0
628630

629-
out = ''
630-
raise ArgumentError, 'recursive array join' if Thread.detect_recursion self do
631+
out = +''
632+
raise ArgumentError, +'recursive array join' if Thread.detect_recursion self do
631633
sep = sep.nil? ? $, : StringValue(sep)
632634

633635
# We've manually unwound the first loop entry for performance
@@ -687,7 +689,7 @@ def last(n=undefined)
687689
n = Truffle::Type.coerce_to_collection_index n
688690
return [] if n == 0
689691

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

692694
n = size if n > size
693695
Array.new self[-n..-1]
@@ -791,7 +793,7 @@ def product(*args)
791793
sum = args.inject(size) { |n, x| n * x.size }
792794

793795
unless Truffle.invoke_primitive(:integer_fits_into_long, sum)
794-
raise RangeError, 'product result is too large'
796+
raise RangeError, +'product result is too large'
795797
end
796798

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

990992
def rand(size)
991993
random = Truffle::Type.coerce_to_collection_index @rng.rand(size)
992-
raise RangeError, 'random value must be >= 0' if random < 0
993-
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
994996

995997
random
996998
end
@@ -1013,7 +1015,7 @@ def sample(count=undefined, options=undefined)
10131015
end
10141016

10151017
if count and count < 0
1016-
raise ArgumentError, 'count must be greater than 0'
1018+
raise ArgumentError, +'count must be greater than 0'
10171019
end
10181020

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

11391141
def drop(n)
11401142
n = Truffle::Type.coerce_to_collection_index n
1141-
raise ArgumentError, 'attempt to drop negative size' if n < 0
1143+
raise ArgumentError, +'attempt to drop negative size' if n < 0
11421144

11431145
new_size = size - n
11441146
return [] if new_size <= 0
@@ -1181,7 +1183,7 @@ def transpose
11811183
max ||= ary.size
11821184

11831185
# Catches too-large as well as too-small (for which #fetch would suffice)
1184-
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
11851187

11861188
ary.size.times do |i|
11871189
entry = (out[i] ||= [])
@@ -1305,7 +1307,7 @@ def recursively_flatten(array, out, max_levels = -1)
13051307
end
13061308
end
13071309

1308-
raise ArgumentError, 'tried to flatten recursive array' if recursion
1310+
raise ArgumentError, +'tried to flatten recursive array' if recursion
13091311
modified
13101312
end
13111313
private :recursively_flatten
@@ -1502,7 +1504,7 @@ def isort_block!(left, right, block)
15021504
block_result = block.call(el1, el2)
15031505

15041506
if block_result.nil?
1505-
raise ArgumentError, 'block returned nil'
1507+
raise ArgumentError, +'block returned nil'
15061508
elsif block_result > 0
15071509
self[j] = el1
15081510
self[j - 1] = el2

src/main/ruby/core/complex.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#
@@ -56,7 +58,7 @@ class Complex < Numeric
5658

5759
def self.convert(real, imag = undefined)
5860
if nil.equal?(real) || nil.equal?(imag)
59-
raise TypeError, 'cannot convert nil into Complex'
61+
raise TypeError, +'cannot convert nil into Complex'
6062
end
6163
imag = nil if undefined.equal?(imag)
6264

@@ -103,13 +105,13 @@ def Complex.generic?(other) # :nodoc:
103105
end
104106

105107
def Complex.rect(real, imag=0)
106-
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)
107109
new(real, imag)
108110
end
109111
class << self; alias_method :rectangular, :rect end
110112

111113
def Complex.polar(r, theta=0)
112-
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)
113115

114116
Complex(r*Math.cos(theta), r*Math.sin(theta))
115117
end

src/main/ruby/core/complexifier.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#

src/main/ruby/core/configuration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2007-2015, Evan Phoenix and contributors
24
# All rights reserved.
35
#
@@ -33,7 +35,7 @@ def initialize
3335

3436
def get_variable(name)
3537
Truffle.primitive :vm_get_config_item
36-
raise PrimitiveFailure, 'Truffle::Configuration#get_variable primitive failed'
38+
raise PrimitiveFailure, +'Truffle::Configuration#get_variable primitive failed'
3739
end
3840

3941
def section(section, &block)

src/main/ruby/core/dir.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -56,7 +58,7 @@ def initialize(path, options=undefined)
5658
end
5759

5860
private def ensure_open
59-
raise IOError, 'closed directory' if closed?
61+
raise IOError, +'closed directory' if closed?
6062
end
6163

6264
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -118,7 +120,7 @@ class << self
118120
end
119121

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

123125
enc = find(enc)
124126
set_alias_index 'external', enc

0 commit comments

Comments
 (0)