Skip to content

Define checkindex for AbstractOneTo #58680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jun 9, 2025

This generalizes the checkindex method for OneTo to AbstractOneTo

@nsajko
Copy link
Contributor

nsajko commented Jun 9, 2025

Not sure if the PR is buggy or just exposes pre-existing bug, but this fails on many or all platforms:

Error During Test at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/test/subarray.jl:916
  Test threw exception
  Expression: stringmime("text/plain", v; context = :limit => true) == "$(Infinity())-element view(::$(OneToInf{Int}), 1:1:$(Infinity())) with eltype $(Int) with indices 1:1:$(Infinity()):\n  1\n  2\n  3\n  4\n  5\n  6\n  7\n  8\n  9\n 10\n  ⋮"
  MethodError: no method matching Main.InfiniteArrays.Infinity(::Int64)
  The type `Main.InfiniteArrays.Infinity` exists, but no method is defined for this combination of argument types when trying to construct it.
  Closest candidates are:
    (::Type{T})(::T) where T<:Number
     @ Core boot.jl:1013
    Main.InfiniteArrays.Infinity()
     @ Main.InfiniteArrays /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/test/testhelpers/InfiniteArrays.jl:18
    (::Type{<:Integer})(!Matched::Sockets.IPAddr)
     @ Sockets /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/stdlib/v1.13/Sockets/src/IPAddr.jl:11
    ...
  Stacktrace:
    [1] convert(::Type{Main.InfiniteArrays.Infinity}, x::Int64)
      @ Base ./number.jl:7
    [2] oftype(x::Main.InfiniteArrays.Infinity, y::Int64)
      @ Base ./essentials.jl:699
    [3] zero(x::Main.InfiniteArrays.Infinity)
      @ Base ./number.jl:357
    [4] unsigned(x::Main.InfiniteArrays.Infinity)
      @ Base ./int.jl:217
    [5] checkindex(::Type{Bool}, inds::Main.InfiniteArrays.OneToInf{Int64}, i::Int64)
      @ Base ./abstractarray.jl:752
    [6] checkindex(::Type{Bool}, inds::Main.InfiniteArrays.OneToInf{Int64}, i::UnitRange{Int64})
      @ Base ./abstractarray.jl:755
    [7] checkbounds
      @ ./abstractarray.jl:687 [inlined]
    [8] checkbounds
      @ ./abstractarray.jl:697 [inlined]
    [9] getindex
      @ ./range.jl:993 [inlined]
   [10] _print_matrix(io::IOContext{IOBuffer}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::Main.InfiniteArrays.OneToInf{Int64}, colsA::UnitRange{Int64})
      @ Base ./arrayshow.jl:195
   [11] print_matrix (repeats 2 times)
      @ ./arrayshow.jl:171 [inlined]
   [12] print_array
      @ ./arrayshow.jl:358 [inlined]
   [13] show(io::IOContext{IOBuffer}, ::MIME{Symbol("text/plain")}, X::SubArray{Int64, 1, Main.InfiniteArrays.OneToInf{Int64}, Tuple{Main.InfiniteArrays.OneToInf{Int64}}, true})
      @ Base ./arrayshow.jl:399
   [14] __binrepr
      @ ./multimedia.jl:173 [inlined]
   [15] _textrepr(m::MIME{Symbol("text/plain")}, x::SubArray{Int64, 1, Main.InfiniteArrays.OneToInf{Int64}, Tuple{Main.InfiniteArrays.OneToInf{Int64}}, true}, context::Pair{Symbol, Bool})
      @ Base.Multimedia ./multimedia.jl:163
   [16] #stringmime#9
      @ /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/stdlib/v1.13/Base64/src/Base64.jl:44 [inlined]
   [17] stringmime(m::String, x::SubArray{Int64, 1, Main.InfiniteArrays.OneToInf{Int64}, Tuple{Main.InfiniteArrays.OneToInf{Int64}}, true}; context::Pair{Symbol, Bool})
      @ Base64 /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/stdlib/v1.13/Base64/src/Base64.jl:45
   [18] top-level scope
      @ /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/test/subarray.jl:910
   [19] macro expansion
      @ /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/stdlib/v1.13/Test/src/Test.jl:1833 [inlined]
   [20] macro expansion
      @ /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/test/subarray.jl:916 [inlined]
   [21] macro expansion
      @ /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-d6b34b32b4/share/julia/stdlib/v1.13/Test/src/Test.jl:727 [inlined]

@nsajko nsajko added the ranges Everything AbstractRange label Jun 9, 2025
@jishnub
Copy link
Member Author

jishnub commented Jun 16, 2025

This PR assumes that unsigned(last(inds)) is defined for inds::AbstractOneTo{<:BitInteger}, but it seems this isn't the case for InfOneTo(). This is a non-standard case since last(inds) isn't well-defined, and I guess we may special-case unsigned for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ranges Everything AbstractRange
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants