Skip to content

Commit c73f22b

Browse files
Zachary ChristensenZachary Christensen
authored andcommitted
Add appropriate interface for ranges
1 parent 3935694 commit c73f22b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/ArrayInterface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ismutable(x) = ismutable(typeof(x))
1616

1717
ismutable(::Type{<:AbstractArray}) = true
1818
ismutable(::Type{<:Number}) = false
19+
ismutable(::Type{<:AbstractRange}) = false
1920

2021
# Piracy
2122
function Base.setindex(x::AbstractArray,v,i...)
@@ -41,6 +42,7 @@ Query whether a type can use `setindex!`
4142
"""
4243
can_setindex(x) = true
4344
can_setindex(x::AbstractArray) = can_setindex(typeof(x))
45+
can_setindex(::Type{<:AbstractRange}) = false
4446

4547
"""
4648
fast_scalar_indexing(x)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ArrayInterface: has_sparsestruct, findstructralnz, fast_scalar_indexing
66
using StaticArrays
77
@test ArrayInterface.ismutable(@SVector [1,2,3]) == false
88
@test ArrayInterface.ismutable(@MVector [1,2,3]) == true
9+
@test ArrayInterface.ismutable(1:10) == false
910

1011
using LinearAlgebra, SparseArrays
1112

0 commit comments

Comments
 (0)