- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.7k
Description
Greetings...
This is not a major issue, but potentially reflects some underlying bug and is certainly confusing: when creating a Dict with a generator expression and an exception occurs, for some reason  the generator restarts until it hits the exception a second time.  Once it hits the exception a second time, it stops, thankfully.  For example (using @show to track execution) Dict(x => sqrt(@show x) for x=[1,2,3,4,-5,6]) does everything (but the 6) twice.  I would have expected it to immediately error out, but...
julia> Dict(x => sqrt(@show x) for x=[1,2,3,4,-5,6])
x = 1
x = 2
x = 3
x = 4
x = -5
x = 1
x = 2
x = 3
x = 4
x = -5
ERROR: DomainError with -5.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] #21 at ./show.jl:576 [inlined]
 [5] iterate at ./generator.jl:47 [inlined]
 [6] _all(::getfield(Base, Symbol("##238#240")), ::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##21#22"))}, ::Colon) at ./reduce.jl:744
 [7] all at ./reduce.jl:732 [inlined]
 [8] Dict(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##21#22"))}) at ./dict.jl:130
 [9] top-level scope at REPL[7]:1
caused by [exception 1]
DomainError with -5.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] #21 at ./show.jl:576 [inlined]
 [5] iterate at ./generator.jl:47 [inlined]
 [6] Dict{Int64,Float64}(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##21#22"))}) at ./dict.jl:103
 [7] dict_with_eltype at ./abstractdict.jl:538 [inlined]
 [8] dict_with_eltype at ./abstractdict.jl:545 [inlined]
 [9] Dict(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##21#22"))}) at ./dict.jl:128
 [10] top-level scope at REPL[7]:1In my case an exception occurred near the end of a calculation that should have taken 30 minutes. I started getting suspicious when it was still running after 40 minutes, even more so when I noticed it was re-doing parts of the job that should have been finished earlier. Granted I of course should have written code that didn't crash, but still. :)
Many thanks for a great programming environment...
Version info, if that helps. (The same issue also occurs on 1.3.0-rc1.0)
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)