Skip to content

Commit 35c6f62

Browse files
authored
Fix incorrect variable in repeat (#88)
* Fix incorrect variable in `repeat` * add testcase
1 parent 618df72 commit 35c6f62

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/InlineStrings.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ summed_type(a::Type{<:SmallInlineStrings}, b::Type{<:SmallInlineStrings}) = summ
616616
function Base.repeat(x::T, r::Integer) where {T <: InlineString}
617617
r < 0 && throw(ArgumentError("can't repeat a string $r times"))
618618
r == 0 && return ""
619-
r == 1 && return s
619+
r == 1 && return x
620620
n = sizeof(x)
621621
out = Base._string_n(n * r)
622622
if n == 1 # common case: repeating a single-byte string

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ for S in SUBTYPES
257257
end
258258
end
259259

260+
# repeat one-time should return the same object
261+
@test repeat(InlineString("abc"), 1) === InlineString("abc")
262+
260263
# can't contain NUL when converting to Cstring
261264
@test_throws ArgumentError Base.cconvert(Cstring, InlineString("a\0c"))
262265

0 commit comments

Comments
 (0)