Skip to content

Commit 20673d9

Browse files
tkoolentkelman
authored andcommitted
Make Colon immutable. Fixes 18034.
(cherry picked from commit 06b171d) ref #18036
1 parent 1d566a9 commit 20673d9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/essentials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function isassigned(v::SimpleVector, i::Int)
202202
end
203203

204204
# index colon
205-
type Colon
205+
immutable Colon
206206
end
207207
const (:) = Colon()
208208

test/subarray.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,15 @@ u = (1,2:3)
484484
let size=(x,y)-> error("should not happen")
485485
@test X[1:end,2,2] == @view X[1:end,2,2]
486486
end
487+
488+
# issue #18034
489+
# ensure that it is possible to create an isbits, LinearFast view of an immutable Array
490+
let
491+
immutable ImmutableTestArray{T, N} <: Base.DenseArray{T, N}
492+
end
493+
Base.size(::Union{ImmutableTestArray, Type{ImmutableTestArray}}) = (0, 0)
494+
Base.linearindexing(::Union{ImmutableTestArray, Type{ImmutableTestArray}}) = Base.LinearFast()
495+
a = ImmutableTestArray{Float64, 2}()
496+
@test Base.linearindexing(view(a, :, :)) == Base.LinearFast()
497+
@test isbits(view(a, :, :))
498+
end

0 commit comments

Comments
 (0)