Skip to content

Commit 47de9c9

Browse files
authored
Merge pull request #25 from xiaodaigh/bugfix/vcat_promote_rule
fixed
2 parents 8ff5af2 + 04bfac2 commit 47de9c9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/base.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ function Base.cmp(a::ShortString{S}, b::ShortString{S}) where S
104104
end
105105

106106
promote_rule(::Type{String}, ::Type{ShortString{S}}) where S = String
107-
promote_rule(::Type{ShortString{T}}, ::Type{ShortString{S}}) where {T,S} = ShortString{promote_rule(T,S)}
107+
108+
function promote_rule(::Type{ShortString{T}}, ::Type{ShortString{S}}) where {T,S}
109+
if sizeof(T) >= sizeof(S)
110+
return ShortString{promote_rule(T,S)}
111+
else
112+
return ShortString{promote_rule(S,T)}
113+
end
114+
end
108115

109116
size_content(s::ShortString) = s.size_content
110117

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ end
105105

106106
@test_throws ErrorException ShortString3(ShortString7("123456"))
107107
end
108+
109+
@testset "promote rule" begin
110+
@test vcat(ShortString3["ab", "cd"], ShortString7["abcd", "efgc"]) == vcat(ShortString3["ab", "cd"], ["abcd", "efgc"])
111+
@test vcat(ShortString3["ab", "cd"], ShortString7["abcd", "efgc"]) == vcat(["ab", "cd"], ShortString7["abcd", "efgc"])
112+
end

0 commit comments

Comments
 (0)