Julia: allunique(('a':1:'c')[1:2]) errors

Created on 4 Mar 2020  ·  2Comments  ·  Source: JuliaLang/julia

I didn't find a bug report for this elsewhere. I'm on 1.3.1 with Mac OS Catalina

julia> allunique(('a':1:'c')[1:2])
ERROR: MethodError: no method matching zero(::Type{Char})
Closest candidates are:
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{LibGit2.GitHash}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/LibGit2/src/oid.jl:220
  zero(::Type{Pkg.Resolve.VersionWeights.VersionWeight}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Pkg/src/resolve/VersionWeights.jl:19
  ...
bug collections good first issue help wanted

Most helpful comment

Adding following to set.jl fixes the bug:

allunique(r::StepRangeLen{T,R,S}) where {T,R,S} = (step(r) != zero(S)) || (length(r) <= 1)

because there is no zero for Char in the AbstractRange{Char} fallback. (I'm traveling so no time for a PR...)

All 2 comments

Adding following to set.jl fixes the bug:

allunique(r::StepRangeLen{T,R,S}) where {T,R,S} = (step(r) != zero(S)) || (length(r) <= 1)

because there is no zero for Char in the AbstractRange{Char} fallback. (I'm traveling so no time for a PR...)

That seems like the right fix here. The failing case make a natural test to add.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

i-apellaniz picture i-apellaniz  ·  3Comments

arshpreetsingh picture arshpreetsingh  ·  3Comments

yurivish picture yurivish  ·  3Comments

StefanKarpinski picture StefanKarpinski  ·  3Comments

iamed2 picture iamed2  ·  3Comments