diff --git a/base/char.jl b/base/char.jl index 12a4bc0ae504c..c99498582b349 100644 --- a/base/char.jl +++ b/base/char.jl @@ -42,6 +42,10 @@ isless(x::Integer, y::Char) = isless(x, UInt32(y)) +(x::Char, y::Integer) = Char(Int32(x) + Int32(y)) +(x::Integer, y::Char) = y + x +Base.promote_op{I<:Integer}(::Base.SubFun, ::Type{Char}, ::Type{I}) = Char +Base.promote_op{I<:Integer}(::Base.AddFun, ::Type{Char}, ::Type{I}) = Char +Base.promote_op{I<:Integer}(::Base.AddFun, ::Type{I}, ::Type{Char}) = Char + bswap(x::Char) = Char(bswap(UInt32(x))) print(io::IO, c::Char) = (write(io, c); nothing) diff --git a/test/char.jl b/test/char.jl index 838466a313c12..0d2f55e3f659f 100644 --- a/test/char.jl +++ b/test/char.jl @@ -13,6 +13,13 @@ # should be swapped @test bswap('\U10200') == '\U20100' +@test 'b' + 1 == 'c' +@test typeof('b' + 1) == Char +@test 1 + 'b' == 'c' +@test typeof(1 + 'b') == Char +@test 'b' - 1 == 'a' +@test typeof('b' - 1) == Char + let numberchars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] @@ -171,3 +178,18 @@ end #end of let block @test convert(Signed, 'A') === Int32(65) @test convert(Unsigned, 'A') === UInt32(65) + +# issue #14573 +let + array = ['a', 'b', 'c'] + [1, 2, 3] + @test array == ['b', 'd', 'f'] + @test eltype(array) == Char + + array = [1, 2, 3] + ['a', 'b', 'c'] + @test array == ['b', 'd', 'f'] + @test eltype(array) == Char + + array = ['a', 'b', 'c'] - [0, 1, 2] + @test array == ['a', 'a', 'a'] + @test eltype(array) == Char +end