How would static types help with that? Whether your indexing range starts with zero or one or something else isn't necessarily encoded in the type domain. `1:length(A)` is just a range of `Int`s.
Why not encode the starting offset into the type domain? Or at least distinguish between normal and unusual. Then the function signature can restrict to 1-offset arrays if that is what it assumes internally.
You could prevent this problem using Julia's type system. The `AbstractArray` might have been too broad. Based on the chronology of the code that might not have been apparent. See other threads for details.
Another way would be to treat `firstindex` as a trait and dispatch on that.
```
julia> f(A::AbstractArray) = f(A, Val(firstindex(A)))
f (generic function with 1 method)
julia> f(A::AbstractArray, firstindex::Val{1}) = println(A[1:length(A)])
f (generic function with 2 methods)
julia> f(A::AbstractArray, firstindex::Val{T}) where T = error("Indexing for array does not start at 1")
f (generic function with 3 methods)
julia> f(A::AbstractArray, firstindex::Val{0}) = println("So you like 0-based indexing?")
f (generic function with 4 methods)
julia> f([1,2,3,4])
[1, 2, 3, 4]
julia> using OffsetArrays
julia> f(OffsetArray(1:10, 1))
ERROR: Indexing for array does not start at 1
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:33
[2] f(A::OffsetVector{Int64, UnitRange{Int64}}, #unused#::Val{2})
@ Main .\REPL[5]:1
[3] f(A::OffsetVector{Int64, UnitRange{Int64}})
@ Main .\REPL[3]:1
[4] top-level scope
@ REPL[9]:1
julia> f(OffsetArray(1:10, -1))
So you like 0-based indexing?
```
That means disallowing indexing with integers, I presume? Since an integer can take the values 0 or 1 equally. And what about the other end of the array. Must every index be restricted by type to be located in the acceptable range?