Skip to content

Stack overflow when broadcasting results in StaticInt eltype #1

@Tokazama

Description

@Tokazama

Found this...

julia> import ArrayInterface: StaticInt

julia> r = StaticInt(1):4
StaticInt{1}():StaticInt{1}():4

julia> broadcast(-, r, StaticInt(1))
ERROR: StackOverflowError:
Stacktrace:
 [1] UnitRange{StaticInt{0}}(::StaticInt{0}, ::StaticInt{3}) at /Users/zchristensen/.julia/packages/ArrayInterface/NbkVT/src/static.jl:108 (repeats 79984 times)

...and traced the issue back to Base._range assuming that UnitRange should be formed with an element type that is a StaticInt.

The easiest way to fix this would be our own Base._range(::StaticInt, ...), but I'm not sure if that's a good entry point since it's not public API.

Edit:
also found this

julia> (StaticInt(1):10)[1:2:6]
ERROR: MethodError: no method matching StepRange{StaticInt{1},Int64}(::StaticInt{1}, ::Int64, ::StaticInt{5})
Closest candidates are:
  StepRange{StaticInt{1},Int64}(::T, ::S, ::T) where {T, S} at range.jl:204
Stacktrace:
 [1] _rangestyle(::Base.Ordered, ::Base.ArithmeticWraps, ::StaticInt{1}, ::Int64, ::Int64) at ./range.jl:118
 [2] _range at ./range.jl:116 [inlined]
 [3] #range#43 at ./range.jl:91 [inlined]
 [4] getindex(::ArrayInterface.OptionallyStaticUnitRange{StaticInt{1},Int64}, ::StepRange{Int64,Int64}) at ./range.jl:713
 [5] top-level scope at REPL[26]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions