Skip to content

Commit 2ebbb2b

Browse files
authored
Fix firstindex in replace_ref_begin_end (fixes #41630) (#41695)
1 parent b458894 commit 2ebbb2b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

base/views.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function replace_ref_begin_end_!(ex, withex)
4242
n = 1
4343
J = lastindex(ex.args)
4444
for j = 2:J
45-
exj, used = replace_ref_begin_end_!(ex.args[j], (:($firstindex($S)),:($lastindex($S,$n))))
45+
exj, used = replace_ref_begin_end_!(ex.args[j], (:($firstindex($S,$n)),:($lastindex($S,$n))))
4646
used_S |= used
4747
ex.args[j] = exj
4848
if isa(exj,Expr) && exj.head === :...

test/offsetarray.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,3 +801,24 @@ end
801801
@test reshape(a, :) === a
802802
@test reshape(a, (:,)) === a
803803
end
804+
805+
@testset "issue #41630: replace_ref_begin_end!/@view on offset-like arrays" begin
806+
x = OffsetArray([1 2; 3 4], -10:-9, 9:10) # 2×2 OffsetArray{...} with indices -10:-9×9:10
807+
808+
# begin/end with offset indices
809+
@test (@view x[begin, 9])[] == 1
810+
@test (@view x[-10, end])[] == 2
811+
@test (@view x[-9, begin])[] == 3
812+
@test (@view x[end, 10])[] == 4
813+
@test (@view x[begin, begin])[] == 1
814+
@test (@view x[begin, end])[] == 2
815+
@test (@view x[end, begin])[] == 3
816+
@test (@view x[end, end])[] == 4
817+
818+
# nested usages of begin/end
819+
y = OffsetArray([-10, -9], (5,))
820+
@test (@view x[begin, -y[end]])[] == 1
821+
@test (@view x[y[begin], end])[] == 2
822+
@test (@view x[end, -y[end]])[] == 3
823+
@test (@view x[y[end], end])[] == 4
824+
end

0 commit comments

Comments
 (0)