Skip to content

Commit 5b9cd81

Browse files
committed
[GR-20446] Fix Numeric#step step argument conversion.
PullRequest: truffleruby/1268
2 parents 49f199a + d29da0a commit 5b9cd81

File tree

4 files changed

+9
-27
lines changed

4 files changed

+9
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Bug fixes:
7171
* Fixed argument handling in `Kernel.printf`.
7272
* Fixed character length after conversion to binary from a non-US-ASCII String.
7373
* Fixed issue with installing latest bundler (#1880).
74+
* Fixed type conversion for `Numeric#step` `step` parameter.
7475

7576
Compatibility:
7677

spec/tags/core/numeric/step_tags.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
1-
fails:Numeric#step with positional args when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
2-
fails:Numeric#step with positional args when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
3-
fails:Numeric#step with positional args when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
4-
fails:Numeric#step with positional args when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
5-
fails:Numeric#step with keyword arguments when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
6-
fails:Numeric#step with keyword arguments when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
7-
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
8-
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
9-
fails:Numeric#step with mixed arguments when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
10-
fails:Numeric#step with mixed arguments when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
11-
fails:Numeric#step with mixed arguments when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
12-
fails:Numeric#step with mixed arguments when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
131
fails:Numeric#step with positional args when no block is given returns an Enumerator::ArithmeticSequence when step is 0
142
fails:Numeric#step with positional args when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self > stop
153
fails:Numeric#step with positional args when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self < stop
16-
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
17-
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
18-
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
19-
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
204
fails:Numeric#step with positional args when no block is given returns an Enumerator::ArithmeticSequence when step is 0.0
215
fails:Numeric#step with positional args when no block is given returned Enumerator::ArithmeticSequence size is infinity when step is 0
226
fails:Numeric#step with positional args when no block is given returned Enumerator::ArithmeticSequence size is infinity when step is 0.0
237
fails:Numeric#step with positional args when no block is given returned Enumerator::ArithmeticSequence type returns an instance of Enumerator::ArithmeticSequence
248
fails:Numeric#step with keyword arguments when no block is given returns an Enumerator::ArithmeticSequence when step is 0
259
fails:Numeric#step with keyword arguments when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self > stop
2610
fails:Numeric#step with keyword arguments when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self < stop
27-
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
28-
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
29-
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
30-
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
3111
fails:Numeric#step with mixed arguments when no block is given returns an Enumerator::ArithmeticSequence when step is 0
3212
fails:Numeric#step with mixed arguments when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self > stop
3313
fails:Numeric#step with mixed arguments when no block is given returns an Enumerator::ArithmeticSequence when not passed a block and self < stop
34-
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError when step is a numeric representation
35-
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an ArgumentError with step as an alphanumeric string
36-
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
37-
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ def self.step_fetch_args(value, limit, step, uses_kwargs)
110110
raise ArgumentError, "step can't be 0" if step == 0
111111
end
112112

113-
step = Truffle::Type.coerce_to_int(step) unless Numeric === step
113+
unless Numeric === step
114+
coerced = Truffle::Type.check_funcall(step, :>, [0])
115+
raise TypeError, "0 can't be coerced into #{Truffle::Type.object_class(step)}" if TrufflePrimitive.undefined?(coerced)
116+
step = coerced
117+
end
118+
114119
desc = step < 0
115120
default_limit = desc ? -Float::INFINITY : Float::INFINITY
116121

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def self.check_funcall(recv, meth, args = [])
303303
def self.check_funcall_default(recv, meth, args, default)
304304
if Truffle::Interop.foreign?(recv)
305305
if recv.respond_to?(meth)
306-
return recv.__send__(meth)
306+
return recv.__send__(meth, *args)
307307
else
308308
return default
309309
end
@@ -313,7 +313,7 @@ def self.check_funcall_default(recv, meth, args, default)
313313
unless check_funcall_callable(recv, meth)
314314
return check_funcall_missing(recv, meth, args, respond, default, true);
315315
end
316-
recv.__send__(meth)
316+
recv.__send__(meth, *args)
317317
end
318318

319319
def self.check_funcall_respond_to(obj, meth, priv)

0 commit comments

Comments
 (0)