Skip to content

Commit 013457b

Browse files
make !isequal('x', 120) and eprecate Int-Char comparisons, 'x' == 120
See #15983 (comment)
1 parent 2309198 commit 013457b

19 files changed

+61
-52
lines changed

base/LineEdit.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1325,11 +1325,11 @@ AnyDict(
13251325
i = position(buf)
13261326
if i != 0
13271327
c = buf.data[i]
1328-
if c == '\n' || c == '\t' ||
1328+
if c == UInt8('\n') || c == UInt8('\t') ||
13291329
# hack to allow path completion in cmds
13301330
# after a space, e.g., `cd <tab>`, while still
13311331
# allowing multiple indent levels
1332-
(c == ' ' && i > 3 && buf.data[i-1] == ' ')
1332+
(c == UInt8(' ') && i > 3 && buf.data[i-1] == UInt8(' '))
13331333
edit_insert(s, " "^4)
13341334
return
13351335
end

base/REPL.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function hist_from_file(hp, file)
360360
while !isempty(line)
361361
push!(lines, chomp(line[2:end]))
362362
eof(file) && break
363-
ch = Base.peek(file)
363+
ch = Char(Base.peek(file))
364364
ch == ' ' && error(munged_history_message, countlines)
365365
ch != '\t' && break
366366
line = hist_getline(file)

base/char.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ isempty(c::Char) = false
3030
in(x::Char, y::Char) = x == y
3131

3232
==(x::Char, y::Char) = UInt32(x) == UInt32(y)
33-
==(x::Char, y::Integer) = UInt32(x) == y
34-
==(x::Integer, y::Char) = x == UInt32(y)
35-
36-
isless(x::Char, y::Char) = isless(UInt32(x), UInt32(y))
37-
isless(x::Char, y::Integer) = isless(UInt32(x), y)
38-
isless(x::Integer, y::Char) = isless(x, UInt32(y))
33+
isless(x::Char, y::Char) = UInt32(x) < UInt32(y)
3934

4035
-(x::Char, y::Char) = Int(x) - Int(y)
4136
-(x::Char, y::Integer) = Char(Int32(x) - Int32(y))

base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function countlines(io::IO, eol::Char='\n')
2323
while !eof(io)
2424
nb = readbytes!(io, a)
2525
@simd for i=1:nb
26-
@inbounds nl += a[i] == eol
26+
@inbounds nl += a[i] == UInt8(eol)
2727
end
2828
end
2929
nl

base/deprecated.jl

+8
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,14 @@ end
11231123
@deprecate_binding UTF8String String
11241124
@deprecate_binding ByteString String
11251125

1126+
@deprecate ==(x::Char, y::Integer) UInt32(x) == y
1127+
@deprecate ==(x::Integer, y::Char) x == UInt32(y)
1128+
@deprecate isless(x::Char, y::Integer) UInt32(x) < y
1129+
@deprecate isless(x::Integer, y::Char) x < UInt32(y)
1130+
# delete these methods along with deprecations:
1131+
isequal(x::Char, y::Integer) = false
1132+
isequal(x::Integer, y::Char) = false
1133+
11261134
# During the 0.5 development cycle, do not add any deprecations below this line
11271135
# To be deprecated in 0.6
11281136

base/float.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ hash(x::UInt64, h::UInt) = hx(x, Float64(x), h)
337337
hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h)
338338
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
339339

340-
hash(x::Union{Bool,Char,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
340+
hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
341341
hash(x::Float32, h::UInt) = hash(Float64(x), h)
342342

343343
## precision, as defined by the effective number of bits in the mantissa ##

base/markdown/Common/block.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function list(stream::IO, block::MD)
198198
c = read(stream, Char)
199199
if c == '\n'
200200
eof(stream) && break
201-
next = peek(stream)
201+
next = Char(peek(stream)) # ok since we only compare with ASCII
202202
if next == '\n'
203203
break
204204
else

base/markdown/Julia/interp.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99

1010
function interpinner(stream::IO, greedy = false)
1111
startswith(stream, '$') || return
12-
(eof(stream) || peek(stream) in whitespace) && return
12+
(eof(stream) || Char(peek(stream)) in whitespace) && return
1313
try
1414
return Base.parse(stream::IOBuffer, greedy = greedy)
1515
catch e

base/markdown/parse/parse.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function parseinline(stream::IO, md::MD, config::Config)
5151
content = []
5252
buffer = IOBuffer()
5353
while !eof(stream)
54-
char = peek(stream)
54+
# FIXME: this is broken if we're looking for non-ASCII
55+
# characters because peek only returns a single byte.
56+
char = Char(peek(stream))
5557
if haskey(config.inner, char) &&
5658
(inner = parseinline(stream, md, config.inner[char])) !== nothing
5759
c = takebuf_string(buffer)

base/markdown/parse/util.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const whitespace = " \t\r"
1616
Skip any leading whitespace. Returns io.
1717
"""
1818
function skipwhitespace(io::IO; newlines = true)
19-
while !eof(io) && (peek(io) in whitespace || (newlines && peek(io) == '\n'))
19+
while !eof(io) && (Char(peek(io)) in whitespace || (newlines && peek(io) == UInt8('\n')))
2020
read(io, Char)
2121
end
2222
return io
@@ -82,7 +82,7 @@ function startswith(stream::IO, s::AbstractString; eat = true, padding = false,
8282
end
8383

8484
function startswith(stream::IO, c::Char; eat = true)
85-
if !eof(stream) && peek(stream) == c
85+
if !eof(stream) && peek(stream) == UInt8(c)
8686
eat && read(stream, Char)
8787
return true
8888
else
@@ -181,7 +181,7 @@ function parse_inline_wrapper(stream::IO, delimiter::AbstractString; rep = false
181181
startswith(stream, delimiter^n) || return nothing
182182
while startswith(stream, delimiter); n += 1; end
183183
!rep && n > nmin && return nothing
184-
!eof(stream) && peek(stream) in whitespace && return nothing
184+
!eof(stream) && Char(peek(stream)) in whitespace && return nothing
185185

186186
buffer = IOBuffer()
187187
while !eof(stream)

base/precompile.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,6 @@ precompile(Base.launch, (Base.LocalManager, Dict, Array{Base.WorkerConfig, 1}, B
478478
precompile(Base.set_valid_processes, (Array{Int, 1}, ))
479479

480480
# Speed up repl help
481-
sprint(Markdown.term, @doc mean)
481+
# sprint(Markdown.term, @doc mean)
482482
sprint(Docs.repl_search, "mean")
483483
sprint(Docs.repl_corrections, "meen")

base/printf.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo
458458
# print sign
459459
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
460460
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
461-
push!(blk.args, :(neg && write(out, '-')))
461+
push!(blk.args, :(neg && write(out, '-')))
462462
# print zero padding
463463
if padding !== nothing && !('-' in flags) && '0' in flags
464464
push!(blk.args, pad(width, padding, '0'))
@@ -468,7 +468,7 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo
468468
if precision > 0
469469
if inside_g && !('#' in flags)
470470
push!(blk.args, :(endidx = $ndigits;
471-
while endidx > 1 && DIGITS[endidx] == '0'
471+
while endidx > 1 && DIGITS[endidx] == UInt8('0')
472472
endidx -= 1
473473
end;
474474
if endidx > 1

test/char.jl

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#tests for /base/char.jl
44

5-
@test typemin(Char) == 0
5+
@test typemin(Char) == Char(0)
66
@test ndims(Char) == 0
77
@test getindex('a', 1) == 'a'
88
@test_throws BoundsError getindex('a',2)
@@ -133,44 +133,44 @@ let
133133

134134
#isless(x::Char, y::Integer) = isless(UInt32(x), y)
135135
for x in upperchars
136-
@test isless(x, 91) == true
136+
@test isless(x, Char(91)) == true
137137
end
138138

139139
for x in lowerchars
140-
@test isless(x, 123) == true
140+
@test isless(x, Char(123)) == true
141141
end
142142

143143
for x in numberchars
144-
@test isless(x, 66) == true
144+
@test isless(x, Char(66)) == true
145145
end
146146

147147
for x in plane1_playingcards
148-
@test isless(x, 127151) == true
148+
@test isless(x, Char(127151)) == true
149149
end
150150

151151
for x in plane2_cjkpart1
152-
@test isless(x, 131088) == true
152+
@test isless(x, Char(131088)) == true
153153
end
154154

155155
#isless(x::Integer, y::Char) = isless(x, UInt32(y))
156156
for x in upperchars
157-
@test isless(64, x) == true
157+
@test isless(Char(64), x) == true
158158
end
159159

160160
for x in lowerchars
161-
@test isless(96, x) == true
161+
@test isless(Char(96), x) == true
162162
end
163163

164164
for x in numberchars
165-
@test isless(47, x) == true
165+
@test isless(Char(47), x) == true
166166
end
167167

168168
for x in plane1_playingcards
169-
@test isless(127135, x) == true
169+
@test isless(Char(127135), x) == true
170170
end
171171

172172
for x in plane2_cjkpart1
173-
@test isless(131071, x) == true
173+
@test isless(Char(131071), x) == true
174174
end
175175
end #end of let block
176176

@@ -191,3 +191,5 @@ let
191191
@test array == ['a', 'a', 'a']
192192
@test eltype(array) == Char
193193
end
194+
195+
@test !isequal('x', 120)

test/random.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let mt = MersenneTwister()
4242
srand(mt)
4343
@test rand(mt, 0:3:1000) in 0:3:1000
4444
@test issubset(rand!(mt, Array(Int, 100), 0:3:1000), 0:3:1000)
45-
coll = Any[2, UInt128(128), big(619), "string", 'c']
45+
coll = Any[2, UInt128(128), big(619), "string"]
4646
@test rand(mt, coll) in coll
4747
@test issubset(rand(mt, coll, 2, 3), coll)
4848

@@ -315,7 +315,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()])
315315
rand!(rng..., BitArray(5)) ::BitArray{1}
316316
rand!(rng..., BitArray(2, 3)) ::BitArray{2}
317317

318-
for T in [Base.BitInteger_types..., Bool, Char, Float16, Float32, Float64]
318+
for T in [Base.BitInteger_types..., Bool, Float16, Float32, Float64]
319319
a0 = rand(rng..., T) ::T
320320
a1 = rand(rng..., T, 5) ::Vector{T}
321321
a2 = rand(rng..., T, 2, 3) ::Array{T, 2}

test/read.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ f = joinpath(dir, "test.txt")
382382
open(io->write(io, "123"), f, "w")
383383
f1 = open(f)
384384
f2 = Base.Filesystem.open(f, Base.Filesystem.JL_O_RDONLY)
385-
@test read(f1, UInt8) == read(f2, UInt8) == '1'
386-
@test read(f1, UInt8) == read(f2, UInt8) == '2'
387-
@test read(f1, UInt8) == read(f2, UInt8) == '3'
385+
@test read(f1, UInt8) == read(f2, UInt8) == UInt8('1')
386+
@test read(f1, UInt8) == read(f2, UInt8) == UInt8('2')
387+
@test read(f1, UInt8) == read(f2, UInt8) == UInt8('3')
388388
@test_throws EOFError read(f1, UInt8)
389389
@test_throws EOFError read(f2, UInt8)
390390
close(f1)

test/sets.jl

+2
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,5 @@ let s = Set(1:5)
244244
end
245245

246246
@test pop!(Set(1:2), 2, nothing) == 2
247+
248+
@test length(Set(['x',120])) == 2

test/spawn.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN
276276
wait(ready) # wait for writer task to be ready before using `out`
277277
@test nb_available(out) == 0
278278
@test endswith(readuntil(out, '1'), '1')
279-
@test read(out, UInt8) == '\t'
279+
@test Char(read(out, UInt8)) == '\t'
280280
c = UInt8[0]
281281
@test c == read!(out, c)
282282
Base.wait_readnb(out, 1)
@@ -288,7 +288,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN
288288
@test !iswritable(out)
289289
@test !isopen(out)
290290
@test nb_available(out) == 0
291-
@test c == ['w']
291+
@test c == UInt8['w']
292292
@test lstrip(ln2) == "1\thello\n"
293293
@test ln1 == "orld\n"
294294
@test isempty(read(out))

test/strings/basic.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ str = "abcdef\uff\uffff\u10ffffABCDEF"
477477
@test typeof(lowercase(utf16(str))) == UTF16String
478478
@test typeof(lowercase(utf32(str))) == UTF32String
479479

480-
foomap(ch) = (ch > 65)
480+
foomap(ch) = (ch > Char(65))
481481
foobar(ch) = Char(0xd800)
482482
foobaz(ch) = reinterpret(Char, typemax(UInt32))
483483
@test_throws UnicodeError map(foomap, utf16(str))

test/unicode/utf32.jl

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a"
55
u32 = utf32(u8)
66
@test sizeof(u32) == 20
7-
@test length(u32.data) == 6 && u32.data[end] == Char(0)
7+
@test length(u32.data) == 6 && u32.data[end] == 0
88
@test length(u32) == 5
99
@test utf8(u32) == u8
1010
@test collect(u8) == collect(u32)
@@ -181,13 +181,13 @@ for (fun, S, T) in ((utf16, UInt16, UTF16String), (utf32, UInt32, UTF32String))
181181
str = "abcd\0\uff\u7ff\u7fff\U7ffff"
182182
tst = SubString(convert(T,str),4)
183183
cmp = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff']
184-
cmpch = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0']
184+
cmp32 = UInt32['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0']
185185
cmp16 = UInt16[0x0064,0x0000,0x00ff,0x07ff,0x7fff,0xd9bf,0xdfff,0x0000]
186186
x = fun(tst)
187-
cmpx = (S == UInt16 ? cmp16 : cmpch)
187+
cmpx = (S == UInt16 ? cmp16 : cmp32)
188188
@test typeof(tst) == SubString{T}
189189
@test convert(T, tst) == str[4:end]
190-
S != UInt32 && @test convert(Vector{Char}, x) == cmp
190+
@test convert(Vector{Char}, x) == cmp
191191
# Vector{T} / Array{T}
192192
@test convert(Vector{S}, x) == cmpx
193193
@test convert(Array{S}, x) == cmpx
@@ -223,9 +223,9 @@ let str = ascii("this ")
223223
@test typeof(p8) == Ptr{UInt8}
224224
@test unsafe_load(p8,1) == 0x74
225225
@test typeof(p16) == Ptr{UInt16}
226-
@test unsafe_load(p16,1) == 0x0074
226+
@test unsafe_load(p16,1) == 0x74
227227
@test typeof(p32) == Ptr{UInt32}
228-
@test unsafe_load(p32,1) == 't'
228+
@test unsafe_load(p32,1) == 0x74
229229
pa = pointer(str, 2)
230230
p8 = pointer(u8, 2)
231231
p16 = pointer(u16, 2)
@@ -235,10 +235,10 @@ let str = ascii("this ")
235235
@test typeof(p8) == Ptr{UInt8}
236236
@test unsafe_load(p8,1) == 0x68
237237
@test typeof(p16) == Ptr{UInt16}
238-
@test unsafe_load(p16,1) == 0x0068
238+
@test unsafe_load(p16,1) == 0x68
239239
@test typeof(p32) == Ptr{UInt32}
240-
@test unsafe_load(p32,1) == 'h'
241-
s8 = SubString{String}(u8, 3, 5)
240+
@test unsafe_load(p32,1) == 0x68
241+
s8 = SubString{String}(u8, 3, 5)
242242
s16 = SubString{UTF16String}(u16, 3, 5)
243243
s32 = SubString{UTF32String}(u32, 3, 5)
244244
p8 = pointer(s8)
@@ -247,18 +247,18 @@ let str = ascii("this ")
247247
@test typeof(p8) == Ptr{UInt8}
248248
@test unsafe_load(p8,1) == 0x69
249249
@test typeof(p16) == Ptr{UInt16}
250-
@test unsafe_load(p16,1) == 0x0069
250+
@test unsafe_load(p16,1) == 0x69
251251
@test typeof(p32) == Ptr{UInt32}
252-
@test unsafe_load(p32,1) == 'i'
252+
@test unsafe_load(p32,1) == 0x69
253253
p8 = pointer(s8, 2)
254254
p16 = pointer(s16, 2)
255255
p32 = pointer(s32, 2)
256256
@test typeof(p8) == Ptr{UInt8}
257257
@test unsafe_load(p8,1) == 0x73
258258
@test typeof(p16) == Ptr{UInt16}
259-
@test unsafe_load(p16,1) == 0x0073
259+
@test unsafe_load(p16,1) == 0x73
260260
@test typeof(p32) == Ptr{UInt32}
261-
@test unsafe_load(p32,1) == 's'
261+
@test unsafe_load(p32,1) == 0x73
262262
end
263263

264264
@test isvalid(Char['f','o','o','b','a','r'])

0 commit comments

Comments
 (0)