Project

General

Profile

Actions

Bug #20296

closed

Complex(:sym, exception: false) generate exception with weird timing

Added by MaxLap (Maxime Lapointe) 2 months ago. Updated 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116930]

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 #1

Updated by MaxLap (Maxime Lapointe) 2 months ago

  • Description updated (diff)
Actions #2

Updated by MaxLap (Maxime Lapointe) 2 months ago

  • ruby -v set to 3.3.0
Actions #3

Updated by nobu (Nobuyoshi Nakada) 2 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
Actions #4

Updated by nobu (Nobuyoshi Nakada) 2 months ago

  • Status changed from Open to Closed

Applied in changeset git|dc146babf47a84bbd1f176d766637d4a40327019.


[Bug #20296] Clear errinfo when exception: false

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0