Skip to content

Commit

Permalink
Fix join((), ", ") (#27062)
Browse files Browse the repository at this point in the history
This is a simply hack to avoid working with an `Iterators.Stateful(())`, which has problems when trying to stably infer the return type of the error function `next((), _)`. Punts #26871 to just using `Stateful` itself.
  • Loading branch information
mbauman authored and JeffBezanson committed May 14, 2018
1 parent 098f40f commit ca764ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ function join(io::IO, strings, delim, last)
print(io, str)
end
end

function join(io::IO, strings, delim)
a = Iterators.Stateful(strings)
for str in a
Expand All @@ -243,6 +242,9 @@ function join(io::IO, strings, delim)
end
end
join(io::IO, strings) = join(io, strings, "")
# Hack around https://github.com/JuliaLang/julia/issues/26871
join(io::IO, strings::Tuple{}, delim) = nothing
join(io::IO, strings::Tuple{}, delim, last) = nothing

join(strings) = sprint(join, strings)
join(strings, delim) = sprint(join, strings, delim)
Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Base.getindex(::V26163, ::Int) = 0
@test reshape(z, 1) == v == [0]
@test reshape(z, 1, 1) == reshape(v, 1, 1) == fill(0, 1, 1)
@test occursin("1-element reshape", summary(reshape(z, 1)))
@test_broken occursin("0-dimensional reshape", summary(reshape(v, ())))
@test occursin("0-dimensional reshape", summary(reshape(v, ())))
end

@test reshape(1:5, (5,)) === 1:5
Expand Down
5 changes: 4 additions & 1 deletion test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@
end
@testset "join()" begin
@test join([]) == join([],",") == ""
@test_broken join(()) == join((),",") == ""
@test join(()) == join((),",") == ""
@test join(["a"],"?") == "a"
@test join("HELLO",'-') == "H-E-L-L-O"
@test join(1:5, ", ", " and ") == "1, 2, 3, 4 and 5"
@test join(["apples", "bananas", "pineapples"], ", ", " and ") == "apples, bananas and pineapples"
@test_throws MethodError join(1, 2, 3, 4)
@test join(()) == ""
@test join((), ", ") == ""
@test join((), ", ", ", and ") == ""
end

# issue #9178 `join` calls `done()` twice on the iterables
Expand Down

0 comments on commit ca764ea

Please sign in to comment.