Skip to content

Commit 8436494

Browse files
committed
Autocorrect and replace comparisons with true/false by Primitive.true? and Primitive.false?
1 parent a71cf6a commit 8436494

File tree

12 files changed

+20
-20
lines changed

12 files changed

+20
-20
lines changed

lib/truffle/socket/truffle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def self.convert_reverse_lookup(socket = nil, reverse_lookup = nil)
333333
elsif reverse_lookup == :numeric
334334
reverse_lookup = false
335335

336-
elsif reverse_lookup != true and reverse_lookup != false
336+
elsif !Primitive.true?(reverse_lookup) and !Primitive.false?(reverse_lookup)
337337
raise ArgumentError,
338338
"invalid reverse_lookup flag: #{reverse_lookup.inspect}"
339339
end

lib/truffle/truffle/cext.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def rb_filesystem_encoding
633633

634634
def rb_to_encoding_index(enc)
635635
enc = Truffle::Type.coerce_to_encoding(enc)
636-
return -1 if enc == false
636+
return -1 if Primitive.false?(enc)
637637
rb_enc_to_index(enc)
638638
end
639639

@@ -1186,7 +1186,7 @@ def rb_class_new(superclass)
11861186

11871187
def rb_define_class_under(mod, name, superclass)
11881188
# nil is TypeError (checked below), false is ArgumentError
1189-
if Primitive.equal?(false, superclass)
1189+
if Primitive.false?(superclass)
11901190
raise ArgumentError, "no super class for `#{name}'"
11911191
end
11921192

src/main/ruby/truffleruby/core/dir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def glob(pattern, flags = 0, base: nil, sort: true, &block)
266266

267267
matches = []
268268
index = 0
269-
flags |= File::FNM_GLOB_NOSORT if Primitive.equal?(sort, false)
269+
flags |= File::FNM_GLOB_NOSORT if Primitive.false?(sort)
270270

271271
normalized_base = if Primitive.nil? base
272272
nil

src/main/ruby/truffleruby/core/io.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ def fcntl(command, arg = 0)
14611461

14621462
if !arg
14631463
arg = 0
1464-
elsif arg == true
1464+
elsif Primitive.true?(arg)
14651465
arg = 1
14661466
elsif Primitive.is_a?(arg, String)
14671467
raise NotImplementedError, 'cannot handle String'
@@ -1491,7 +1491,7 @@ def ioctl(command, arg = 0)
14911491

14921492
if !arg
14931493
real_arg = 0
1494-
elsif arg == true
1494+
elsif Primitive.true?(arg)
14951495
real_arg = 1
14961496
elsif Primitive.is_a?(arg, String)
14971497
# This could be faster.

src/main/ruby/truffleruby/core/kernel.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def Complex(real, imag = undefined, exception: true)
5454
module_function :Complex
5555

5656
def Float(obj, exception: true)
57-
raise_exception = !Primitive.equal?(exception, false)
57+
raise_exception = !Primitive.false?(exception)
5858
obj = Truffle::Interop.unbox_if_needed(obj)
5959

6060
case obj
@@ -104,7 +104,7 @@ def Integer(obj, base = 0, exception: true)
104104
obj = Truffle::Interop.unbox_if_needed(obj)
105105
converted_base = Truffle::Type.rb_check_to_integer(base, :to_int)
106106
base = Primitive.nil?(converted_base) ? 0 : converted_base
107-
raise_exception = !Primitive.equal?(exception, false)
107+
raise_exception = !Primitive.false?(exception)
108108

109109
if Primitive.is_a?(obj, String)
110110
Primitive.string_to_inum(obj, base, true, raise_exception)

src/main/ruby/truffleruby/core/numeric.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Numeric
3030
include Comparable
3131

3232
def clone(freeze: nil)
33-
if Primitive.equal?(freeze, false)
33+
if Primitive.false?(freeze)
3434
raise ArgumentError, "can't unfreeze #{Primitive.class(self).name}"
3535
end
3636
self

src/main/ruby/truffleruby/core/pre.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def include(mod)
5858
result = Primitive.unbound_method_ruby2_keywords(method)
5959
if Primitive.nil?(result)
6060
warn "Skipping set of ruby2_keywords flag for #{name} (method accepts keywords or method does not accept argument splat)", uplevel: 1
61-
elsif result == false
61+
elsif Primitive.false?(result)
6262
warn "Skipping set of ruby2_keywords flag for #{name} (unknown reason)", uplevel: 1
6363
end
6464
end
@@ -71,7 +71,7 @@ def ruby2_keywords
7171
result = Primitive.proc_ruby2_keywords(self)
7272
if Primitive.nil?(result)
7373
warn 'Skipping set of ruby2_keywords flag for proc (proc accepts keywords or proc does not accept argument splat)', uplevel: 1
74-
elsif result == false
74+
elsif Primitive.false?(result)
7575
warn 'Skipping set of ruby2_keywords flag for proc (unknown reason)', uplevel: 1
7676
end
7777
self

src/main/ruby/truffleruby/core/range.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def bsearch(&block)
112112
return nil if max < min || max == min && self.exclude_end? #-inf.prev_float == -inf!
113113
if max == min
114114
result = yield max
115-
return result == true || result == 0 ? max : nil
115+
return Primitive.true?(result) || result == 0 ? max : nil
116116
end
117117

118118
# max == -Float::INFINITY will already be covered by the comparisons above.
@@ -136,7 +136,7 @@ def bsearch(&block)
136136
if min == -Float::INFINITY
137137
result = yield min
138138
# Find-minimum mode: It's not going to get any smaller than negative infinity.
139-
return min if result == true || result == 0
139+
return min if Primitive.true?(result) || result == 0
140140
return nil if Primitive.is_a?(result, Numeric) && result < 0
141141
min = normalized_begin = -Float::MAX # guaranteed to be <= max
142142
end
@@ -175,12 +175,12 @@ def bsearch(&block)
175175
# max is untested only if it's the end of the range.
176176
# It can only change the result of the search if we haven't found an admissible value yet (+ infinity edge case).
177177
result = yield max
178-
return max if result == true || result == 0
178+
return max if Primitive.true?(result) || result == 0
179179
elsif mid == max && min == normalized_begin
180180
# min is untested only if it's the begin of the range.
181181
result = yield min
182182
# Favor smallest value in case we're in find-minimum mode.
183-
return min if result == true || result == 0
183+
return min if Primitive.true?(result) || result == 0
184184
end
185185

186186
last_admissible

src/main/ruby/truffleruby/core/truffle/complex_operations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
module Truffle
1212
module ComplexOperations
1313
def self.convert_not_real_arguments(real, imag, exception)
14-
raise_exception = !Primitive.equal?(exception, false)
14+
raise_exception = !Primitive.false?(exception)
1515
if Primitive.nil?(real) || Primitive.nil?(imag)
1616
return nil unless raise_exception
1717
raise TypeError, "can't convert nil into Complex"

src/main/ruby/truffleruby/core/truffle/exception_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def self.full_message(exception, highlight, order)
130130
highlight = if Primitive.nil?(highlight)
131131
Exception.to_tty?
132132
else
133-
raise ArgumentError, "expected true of false as highlight: #{highlight}" unless Primitive.equal?(highlight, true) || Primitive.equal?(highlight, false)
134-
!Primitive.equal?(highlight, false)
133+
raise ArgumentError, "expected true of false as highlight: #{highlight}" unless Primitive.true?(highlight) || Primitive.false?(highlight)
134+
!Primitive.false?(highlight)
135135
end
136136

137137
raise ArgumentError, "expected :top or :bottom as order: #{order}" unless Primitive.equal?(order, :top) || Primitive.equal?(order, :bottom)

0 commit comments

Comments
 (0)