Skip to content

Commit 2590e67

Browse files
committed
fixed
1 parent 8ff5af2 commit 2590e67

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/base.jl

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# this is for keeping the basic functionalities
22

3-
import Base:unsafe_getindex, ==, show, promote_rule
3+
import Base:unsafe_getindex, ==, show, promote_rule, promote_eltype
44

55
struct ShortString{T} <: AbstractString where T
66
size_content::T
@@ -104,7 +104,17 @@ 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
115+
116+
promote_eltype(::Vector{ShortString{T}}, ::Vector{ShortString{S}}) where {T,S} =
117+
promote_rule(ShortString{T}, ShortString{S})
108118

109119
size_content(s::ShortString) = s.size_content
110120

test/runtests.jl

+5
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)