Keno / SIUnits.jl

Efficient unit-checked computation
Other
70 stars 26 forks source link

Inconsistent "Error: no promotion exists" #49

Closed mweastwood closed 9 years ago

mweastwood commented 9 years ago

This is my test script

using SIUnits
const si2str = Dict{SIUnits.SIUnit,ASCIIString}()
const str2si = Dict{ASCIIString,SIUnits.SIUnit}()
for (si,str) in ((Meter,"m"),(Second,"s"),(KiloGram,"kg"))
    si2str[si] = str
    str2si[str] = si
end
@show si2str str2si

Most of the time this script works as expected. However, every now and then (I estimate about 25% of the time) I get

$ julia test.jl
Warning: New definition
    convert(Type{SIUnits.SIQuantity{T,m,kg,s,A,K,mol,cd}},T) at /home/mweastwood/.julia/SIUnits/src/SIUnits.jl:134
is ambiguous with:
    convert(Type{T<:Number},Base.Dates.Period) at dates/periods.jl:19.
To fix, define
    convert(Type{SIUnits.SIQuantity{_<:Base.Dates.Period,m,kg,s,A,K,mol,cd}},_<:Base.Dates.Period)
before the new definition.
Warning: New definition
    convert(Type{SIUnits.NonSIQuantity{T,U}},T) at /home/mweastwood/.julia/SIUnits/src/SIUnits.jl:526
is ambiguous with:
    convert(Type{T<:Number},Base.Dates.Period) at dates/periods.jl:19.
To fix, define
    convert(Type{SIUnits.NonSIQuantity{_<:Base.Dates.Period,U}},_<:Base.Dates.Period)
before the new definition.
ERROR: no promotion exists for SIUnits.SIQuantity{SIUnits.SIUnit{0,1,0,0,0,0,0},m,kg,s,A,K,mol,cd} and SIUnits.SIQuantity{SIUnits.SIUnit{0,0,1,0,0,0,0},m,kg,s,A,K,mol,cd}
 in promote_to_super at promotion.jl:154
 in == at promotion.jl:167
 in ht_keyindex2 at dict.jl:543
 in setindex! at dict.jl:580
 in anonymous at no file:5
 in include at ./boot.jl:242
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:312
 in _start at ./client.jl:393
while loading /path/to/test.jl, in expression starting on line 4

I assume this is most likely a Julia error, but I'd like confirmation before I report it.

This is on da9e78d466f42d38bc058914552c0d499c688686 with:

Julia Version 0.4.0-dev+2440
Commit b365c36 (2015-01-03 13:21 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
mweastwood commented 9 years ago

This appears to be enough to trigger the bug:

immutable SIUnit{m,kg,s,A,K,mol,cd} <: Number
end

const Meter    = SIUnit{1,0,0,0,0,0,0}()
const KiloGram = SIUnit{0,1,0,0,0,0,0}()
const Second   = SIUnit{0,0,1,0,0,0,0}()

const si2str = Dict{SIUnit,ASCIIString}()
for (si,str) in ((Meter,"m"),(KiloGram,"kg"),(Second,"s"))
    si2str[si] = str
end