Skip to content

Commit 29ac378

Browse files
committed
disable rand(String, 2, 3)
1 parent 61ace50 commit 29ac378

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/containers.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ end
6565

6666
@make_container(::Type{String}, [n::Integer])
6767

68+
# we disable smthg like rand(String, 2, 3) because it looks to similar to, but is too different
69+
# than, rand(String, 2) (Array of String vs String)
70+
71+
string_error() = throw(ArgumentError(
72+
"rand([rng], String, d1::Integer, d2::Integer, ...) is unsupported,
73+
use rand(rng, make(String), d1, d2, ...) or rand(rng, String, (d1, d2, ...)) instead"))
74+
rand(rng::AbstractRNG, ::Type{String}, n::Integer...) = string_error()
75+
rand( ::Type{String}, n::Integer...) = string_error()
76+
6877
# sparse vectors & matrices
6978
@make_container(::Type{SparseVector}, p::AbstractFloat, m::Integer)
7079
@make_container(::Type{SparseVector}, p::AbstractFloat, d::Dims{1})

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ const spString = Sampler(MersenneTwister, String)
189189
s = rand(rng..., "asd", String)
190190
@test length(s) == 8
191191
@test Set(s) <= Set("asd")
192+
@test_throws ArgumentError rand(rng..., String, 2, 3)
193+
@test_throws ArgumentError rand(rng..., String, 2, 3, 4)
194+
@test_throws ArgumentError rand(rng..., String, 2, 3, 4, 5)
192195

193196
# Tuple
194197
s = rand(rng..., Int, NTuple{3})

0 commit comments

Comments
 (0)