MikeInnes / Lazy.jl

I was gonna maintain this package, but then I got high
Other
469 stars 54 forks source link

Some type piracy in Lazy.jl #86

Open rdeits opened 6 years ago

rdeits commented 6 years ago

I was debugging what I thought was a problem with Interact and Widgets.jl, but it turned out to be some subtle type piracy coming from Lazy.jl. This line: https://github.com/MikeInnes/Lazy.jl/blob/db5a0eb044769d303a58c6582b7205b12e7257ab/src/liblazy.jl

overloads Base.map(f::Function) (since the ls... argument can be empty), which is classic type piracy. For example:

Without Lazy.jl:

julia> map(sin)
ERROR: MethodError: no method matching sin()
Closest candidates are:
  sin(::BigFloat) at mpfr.jl:637
  sin(::Complex{Float16}) at math.jl:951
  sin(::Float16) at math.jl:950
  ...
Stacktrace:
 [1] map(::Base.#sin) at ./abstractarray.jl:1935

With Lazy.jl loaded:

julia> using Lazy

julia> map(sin)
(Error showing value of type Lazy.LazyList:
ERROR: MethodError: no method matching sin()
Closest candidates are:
  sin(::BigFloat) at mpfr.jl:637
  sin(::Complex{Float16}) at math.jl:951
  sin(::Float16) at math.jl:950
  ...
Stacktrace:
 [1] (::Lazy.##59#60{Base.#sin,Tuple{}})() at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:93
 [2] realise!(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:79
 [3] realise(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:84
 [4] (::Lazy.##41#42{Lazy.LazyList,String,Int64})() at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:93
 [5] realise!(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:79
 [6] realise(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:87
 [7] (::Lazy.##37#38{Lazy.LazyList,Lazy.LinkedList})() at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:93
 [8] realise!(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:79
 [9] realise(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:87
 [10] any(::Base.#isempty, ::Tuple{Lazy.LazyList}) at ./reduce.jl:574
 [11] (::Lazy.##59#60{Lazy.##91#92{IOContext{Base.Terminals.TTYTerminal}},Tuple{Lazy.LazyList}})() at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:93
 [12] realise!(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:79
 [13] realise(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:87
 [14] dorun(::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/tail.jl:123
 [15] show(::IOContext{Base.Terminals.TTYTerminal}, ::Lazy.LazyList) at /home/rdeits/.julia/v0.6/Lazy/src/Lazy.jl:149
 [16] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Lazy.LazyList) at ./REPL.jl:122
 [17] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Lazy.LazyList) at ./REPL.jl:125
 [18] display(::Lazy.LazyList) at ./multimedia.jl:218
 [19] eval(::Module, ::Any) at ./boot.jl:235
 [20] print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:144
 [21] print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:129
 [22] (::Base.REPL.#do_respond#16{Bool,Base.REPL.##26#36{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:646
singularitti commented 1 year ago

I just found the same problem! Though I think map(f) = f() is a bad design, this is still a type piracy. In fact, I do not even know I had Lazy.jl installed!