Actions
Bug #20296
closedComplex(:sym, exception: false) generate exception with weird timing
Description
Happens in Ruby 3.2.2, 3.2.3 and 3.3.0 (didn't test others).
Add this to a file and execute it as-is:
3.times { Complex(:sym, exception: false) }
puts "hi"
The output will be:
$ ruby local2.rb
hi
local2.rb:1:in `Complex': can't convert Symbol into Complex (TypeError)
3.times { Complex(:sym, exception: false) }
^^^^^^^^^^^^^^^^^^^^^^
from local2.rb:1:in `block in <main>'
from local2.rb:1:in `times'
from local2.rb:1:in `<main>'
local2.rb:1:in `Complex': can't convert Symbol into Complex (TypeError)
3.times { Complex(:sym, exception: false) }
^^^^^^^^^^^^^^^^^^^^^^
from local2.rb:1:in `block in <main>'
from local2.rb:1:in `times'
from local2.rb:1:in `<main>'
local2.rb:1:in `Complex': can't convert Symbol into Complex (TypeError)
3.times { Complex(:sym, exception: false) }
^^^^^^^^^^^^^^^^^^^^^^
from local2.rb:1:in `block in <main>'
from local2.rb:1:in `times'
from local2.rb:1:in `<main>'
So the exception is still reported (instead of being swallow), but the puts, which is after, had the time to execute first. I can even put a sleep()
in between and the exceptions are still reported after the puts.
In a IRB, there is no exception at all and everything seems to work as expected.
Happens if I pass in an Array too. Doesn't seem to happen with bad strings.
There is also a quadratic behavior somewhere in there. Running the code in an IRB (which doesn't show exceptions), if you double the number of times
in the loop, it takes 4x as long. This is probably related...
Actions
Like0
Like0Like0Like0Like0Like0Like0