Skip to content

Commit e02764c

Browse files
authored
Merge pull request #39488 from JuliaLang/backports-release-1.6
One more backport for 1.6-RC1
2 parents 7bc881c + 28a6984 commit e02764c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

base/subarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,19 @@ compute_offset1(parent::AbstractVector, stride1::Integer, I::Tuple{AbstractRange
380380
# indexing uses the indices along the given dimension.
381381
# If the result is one-dimensional and it's a range, then linear
382382
# indexing might be offset if the index itself is offset
383-
# Otherwise linear indexing always starts with 1.
383+
# Otherwise linear indexing always matches the parent.
384384
compute_offset1(parent, stride1::Integer, I::Tuple) =
385385
(@_inline_meta; compute_offset1(parent, stride1, find_extended_dims(1, I...), find_extended_inds(I...), I))
386386
compute_offset1(parent, stride1::Integer, dims::Tuple{Int}, inds::Tuple{Slice}, I::Tuple) =
387387
(@_inline_meta; compute_linindex(parent, I) - stride1*first(axes(parent, dims[1]))) # index-preserving case
388388
compute_offset1(parent, stride1::Integer, dims, inds::Tuple{AbstractRange}, I::Tuple) =
389389
(@_inline_meta; compute_linindex(parent, I) - stride1*first(axes1(inds[1]))) # potentially index-offsetting case
390390
compute_offset1(parent, stride1::Integer, dims, inds, I::Tuple) =
391-
(@_inline_meta; compute_linindex(parent, I) - stride1) # linear indexing starts with 1
391+
(@_inline_meta; compute_linindex(parent, I) - stride1)
392392
function compute_linindex(parent, I::NTuple{N,Any}) where N
393393
@_inline_meta
394394
IP = fill_to_length(axes(parent), OneTo(1), Val(N))
395-
compute_linindex(1, 1, IP, I)
395+
compute_linindex(first(LinearIndices(parent)), 1, IP, I)
396396
end
397397
function compute_linindex(f, s, IP::Tuple, I::Tuple{ScalarIndex, Vararg{Any}})
398398
@_inline_meta

test/offsetarray.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ let a1 = [11,12,13], a2 = [1 2; 3 4]
110110
@test_throws BoundsError i2[1:2:5]
111111
end
112112

113+
# issue #37274
114+
let a = 1:3
115+
oa = OffsetArray(a, 0:2)
116+
b = @view oa[0]
117+
@test b[] == b[1] == b[1,1] == 1
118+
@test_throws BoundsError b[0]
119+
@test_throws BoundsError b[2]
120+
end
121+
113122
# logical indexing
114123
@test A[A .> 2] == [3,4]
115124
@test_throws BoundsError h[trues(2)]

0 commit comments

Comments
 (0)