Stack overflow error when splatting strings into `join`

I accidentally splatted several strings into join, and got the following behaviour, with many screens of error messages scrolling past:


julia> join('a', 'b', 'c')
"a"

julia> join('a', 'b', 'c', 'd')

ERROR: StackOverflowError:
Stacktrace:
 [1] join(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Vararg{Any,N} where N) at ./strings/io.jl:216
 [2] #sprint#228(::Void, ::Function, ::Int64, ::Function, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Vararg{Any,N} where N) at ./strings/io.jl:66

I just want to understand, is this the kind of thing that should be filed as an issue? It doesn’t seem like the most useful error message.

2 Likes

This goes through

join(IOBuffer(Base.StringVector(0), true, true), 'a', 'b', 'c', 'd')

and that’s why you get the infinite recursion. Passing around args... is useful for compact code, but sometimes leads to cryptic error messages. Perhaps an idiom that allowed passing a bunch of arguments in groups, not unlike COMMON-LISP:&WHOLE, would be helpful?

But you don’t think it’s a reportable bug, but expected behaviour?

I think there is an issue here that is worth discussion, ie how to implement this rather common pattern so that it leads to better output from methods (join(args...) is not really informative), better error reporting, etc. So perhaps open an issue, after checking that it does not exist, about this broader question.

It’s worth reporting, or even better make a PR. It should really be a MethodError and replacing the join(args...) catchall method with specific versions for one to three arguments would solve it. Alternatively a join(io::IO, args...) method could be added to stop the recursion and throw an error.

1 Like

I didn’t ever use join a lot, but according to the documentation it’s supposed to take an array (or any iterable) as input, no?

julia> join(('a', 'b', 'c', 'd'))
"abcd"

julia> join(['a', 'b', 'c', 'd'])
"abcd"

julia> join(["a", "b", "c", "d"])
"abcd"

julia> join(("a", "b", "c", "d"))
"abcd"

Yes, the issue here is the error message…