Skip to content

Commit cbcd71d

Browse files
mortenpiKristofferC
authored andcommitted
Fix Distributed.head_and_tail (JuliaLang/julia#32431)
The last return statement is currently referring to a non-existent s variable. Also fix the related doctest, even though it does not get tested at the moment. (cherry picked from commit a7aa307)
1 parent 93d8eb2 commit cbcd71d

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/pmap.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,11 @@ Return `head`: the first `n` elements of `c`;
238238
and `tail`: an iterator over the remaining elements.
239239
240240
```jldoctest
241-
julia> a = 1:10
242-
1:10
243-
244-
julia> b, c = Base.head_and_tail(a, 3)
245-
([1,2,3],Base.Iterators.Rest{UnitRange{Int64},Int64}(1:10,4))
241+
julia> b, c = Distributed.head_and_tail(1:10, 3)
242+
([1, 2, 3], Base.Iterators.Rest{UnitRange{Int64},Int64}(1:10, 3))
246243
247244
julia> collect(c)
248-
7-element Array{Any,1}:
245+
7-element Array{Int64,1}:
249246
4
250247
5
251248
6
@@ -268,7 +265,7 @@ function head_and_tail(c, n)
268265
i += 1
269266
head[i] = y[1]
270267
end
271-
return head, Iterators.rest(c, s)
268+
return head, Iterators.rest(c, y[2])
272269
end
273270

274271
"""

test/distributed_exec.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,32 @@ let code = """
15471547
@test success(`$(Base.julia_cmd()) --startup-file=no -e $code`)
15481548
end
15491549

1550+
# PR 32431: tests for internal Distributed.head_and_tail
1551+
let (h, t) = Distributed.head_and_tail(1:10, 3)
1552+
@test h == 1:3
1553+
@test collect(t) == 4:10
1554+
end
1555+
let (h, t) = Distributed.head_and_tail(1:10, 0)
1556+
@test h == []
1557+
@test collect(t) == 1:10
1558+
end
1559+
let (h, t) = Distributed.head_and_tail(1:3, 5)
1560+
@test h == 1:3
1561+
@test collect(t) == []
1562+
end
1563+
let (h, t) = Distributed.head_and_tail(1:3, 3)
1564+
@test h == 1:3
1565+
@test collect(t) == []
1566+
end
1567+
let (h, t) = Distributed.head_and_tail(Int[], 3)
1568+
@test h == []
1569+
@test collect(t) == []
1570+
end
1571+
let (h, t) = Distributed.head_and_tail(Int[], 0)
1572+
@test h == []
1573+
@test collect(t) == []
1574+
end
1575+
15501576
# Run topology tests last after removing all workers, since a given
15511577
# cluster at any time only supports a single topology.
15521578
rmprocs(workers())

0 commit comments

Comments
 (0)