Skip to content

Commit bfc4161

Browse files
committed
Fix global tuple iteration
1 parent aef6f57 commit bfc4161

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/iterate.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,20 @@ function _const(x, i)
257257
end
258258

259259
function _global(x, i)
260-
if hastrivia(x) && (headof(first(x.trivia)) === :GLOBAL || headof(first(x.trivia)) === :LOCAL)
261-
oddt_evena(x, i)
260+
if length(x.trivia) > length(x.args) # probably :tuple
261+
if i <= 2
262+
x.trivia[i]
263+
elseif isodd(i)
264+
x.args[div(i - 1, 2)]
265+
else
266+
x.trivia[div(i - 2, 2) + 2]
267+
end
262268
else
263-
odda_event(x, i)
269+
if hastrivia(x) && (headof(first(x.trivia)) === :GLOBAL || headof(first(x.trivia)) === :LOCAL)
270+
oddt_evena(x, i)
271+
else
272+
odda_event(x, i)
273+
end
264274
end
265275
end
266276

test/iterate.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ end
2929
@test x[1] === x.trivia[1]
3030
@test x[2] === x.args[1]
3131
end
32+
33+
@testset "global tuple" begin
34+
x = cst"global (a = 1,b = 2)"
35+
@test length(x) == 6
36+
@test x[1] === x.trivia[1]
37+
@test x[2] === x.trivia[2]
38+
@test x[3] === x.args[1]
39+
@test x[4] === x.trivia[3]
40+
@test x[5] === x.args[2]
41+
@test x[6] === x.trivia[4]
42+
end
43+
3244
@testset "const" begin
3345
x = cst"const a = 1"
3446
@test length(x) == 2

0 commit comments

Comments
 (0)