diff --git a/NEWS.md b/NEWS.md index df81cf5835aa8..ccc2237831d03 100644 --- a/NEWS.md +++ b/NEWS.md @@ -69,6 +69,9 @@ Language changes * The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to `(1<<2)*3` in a future version ([#13079]). + * The precedence of `&` and `|` is deprecated, and will change to match that of + `&&` and `||`. In the meantime, such expressions should be parenthesized ([#5187]). + * The parsing of `<|` is now right associative. `|>` remains left associative ([#24153]). * `{ }` expressions now use `braces` and `bracescat` as expression heads instead diff --git a/base/bitarray.jl b/base/bitarray.jl index 93f4973f3ee56..9813d2b45cc08 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -324,7 +324,7 @@ dumpbitcache(Bc::Vector{UInt64}, bind::Int, C::Vector{Bool}) = ## custom iterator ## start(B::BitArray) = 0 -next(B::BitArray, i::Int) = (B.chunks[_div64(i)+1] & (UInt64(1)<<_mod64(i)) != 0, i+1) +next(B::BitArray, i::Int) = ((B.chunks[_div64(i)+1] & (UInt64(1)<<_mod64(i))) != 0, i+1) done(B::BitArray, i::Int) = i >= length(B) ## similar, fill!, copy! etc ## @@ -702,7 +702,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray) @inbounds C = Bc[i] u = UInt64(1) for j = 1:(i < lc ? 64 : last_chunk_len) - if Imsk & u != 0 + if (Imsk & u) != 0 lx < c && throw_setindex_mismatch(X, c) @inbounds x = convert(Bool, X[c]) C = ifelse(x, C | u, C & ~u) @@ -1068,7 +1068,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if c & u != 0 + if (c & u) != 0 A[ind] = -1 end ind += 1 @@ -1078,7 +1078,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if c & u != 0 + if (c & u) != 0 A[ind] = -1 end ind += 1 @@ -1449,7 +1449,7 @@ function unsafe_bitfindnext(Bc::Vector{UInt64}, start::Integer) mask = _msk64 << within_chunk_start @inbounds begin - if Bc[chunk_start] & mask != 0 + if (Bc[chunk_start] & mask) != 0 return (chunk_start-1) << 6 + trailing_zeros(Bc[chunk_start] & mask) + 1 end @@ -1485,7 +1485,7 @@ function findnextnot(B::BitArray, start::Integer) mask = ~(_msk64 << within_chunk_start) @inbounds if chunk_start < l - if Bc[chunk_start] | mask != _msk64 + if (Bc[chunk_start] | mask) != _msk64 return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1 end for i = chunk_start+1:l-1 @@ -1496,7 +1496,7 @@ function findnextnot(B::BitArray, start::Integer) if Bc[l] != _msk_end(B) return (l-1) << 6 + trailing_ones(Bc[l]) + 1 end - elseif Bc[l] | mask != _msk_end(B) + elseif (Bc[l] | mask) != _msk_end(B) return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1 end return 0 @@ -1530,7 +1530,7 @@ function unsafe_bitfindprev(Bc::Vector{UInt64}, start::Integer) mask = _msk_end(start) @inbounds begin - if Bc[chunk_start] & mask != 0 + if (Bc[chunk_start] & mask) != 0 return (chunk_start-1) << 6 + (64 - leading_zeros(Bc[chunk_start] & mask)) end @@ -1560,7 +1560,7 @@ function findprevnot(B::BitArray, start::Integer) mask = ~_msk_end(start) @inbounds begin - if Bc[chunk_start] | mask != _msk64 + if (Bc[chunk_start] | mask) != _msk64 return (chunk_start-1) << 6 + (64 - leading_ones(Bc[chunk_start] | mask)) end @@ -1608,7 +1608,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if c & u != 0 + if (c & u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1619,7 +1619,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if c & u != 0 + if (c & u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1839,7 +1839,7 @@ function read!(s::IO, B::BitArray) n = length(B) Bc = B.chunks nc = length(read!(s, Bc)) - if length(Bc) > 0 && Bc[end] & _msk_end(n) ≠ Bc[end] + if length(Bc) > 0 && (Bc[end] & _msk_end(n)) ≠ Bc[end] Bc[end] &= _msk_end(n) # ensure that the BitArray is not broken throw(DimensionMismatch("read mismatch, found non-zero bits after BitArray length")) end diff --git a/base/c.jl b/base/c.jl index 61163a93fcbc4..c14ffb3ad5aed 100644 --- a/base/c.jl +++ b/base/c.jl @@ -281,7 +281,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) m += 1 elseif a < 0x800 # 2-byte UTF-8 m += 2 - elseif a & 0xfc00 == 0xd800 && i < length(src) + elseif (a & 0xfc00) == 0xd800 && i < length(src) b = src[i += 1] if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 m += 4 @@ -307,7 +307,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) elseif a < 0x800 # 2-byte UTF-8 dst[j += 1] = 0xc0 | ((a >> 6) % UInt8) dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f) - elseif a & 0xfc00 == 0xd800 && i < n + elseif (a & 0xfc00) == 0xd800 && i < n b = src[i += 1] if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 diff --git a/base/char.jl b/base/char.jl index 717881c37d05c..993e817f502d7 100644 --- a/base/char.jl +++ b/base/char.jl @@ -33,8 +33,8 @@ function UInt32(c::Char) malformed_char(c)::Union{} u &= 0xffffffff >> l1 u >>= t0 - (u & 0x0000007f >> 0) | (u & 0x00007f00 >> 2) | - (u & 0x007f0000 >> 4) | (u & 0x7f000000 >> 6) + ((u & 0x0000007f) >> 0) | ((u & 0x00007f00) >> 2) | + ((u & 0x007f0000) >> 4) | ((u & 0x7f000000) >> 6) end function Char(u::UInt32) diff --git a/base/deprecated.jl b/base/deprecated.jl index d9b2eededd1f1..254c54d755933 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1429,10 +1429,11 @@ end # ::ANY is deprecated in src/method.c # also remove all instances of `jl_ANY_flag` in src/ -# issue #13079 +# issue #13079, #5187 # in julia-parser.scm: # move prec-bitshift after prec-rational -# remove parse-with-chains-warn and bitshift-warn +# move & and | to && and || level +# remove dep-check and related code # update precedence table in doc/src/manual/mathematical-operations.md # deprecate remaining vectorized methods over SparseVectors (zero-preserving) diff --git a/base/filesystem.jl b/base/filesystem.jl index 001a8fcb210bb..8125e7edf11fb 100644 --- a/base/filesystem.jl +++ b/base/filesystem.jl @@ -158,7 +158,7 @@ function read(f::File, ::Type{Char}) while s ≥ l && !eof(f) p = position(f) b = read(f, UInt8) - if b & 0xc0 != 0x80 + if (b & 0xc0) != 0x80 seek(f, p) break end diff --git a/base/float.jl b/base/float.jl index a441be412b26a..d09fc29499aed 100644 --- a/base/float.jl +++ b/base/float.jl @@ -101,7 +101,7 @@ function Float64(x::Int128) y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 - reinterpret(Float64, s | d + y) + reinterpret(Float64, (s | d) + y) end function Float32(x::UInt128) @@ -131,7 +131,7 @@ function Float32(x::Int128) y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 - reinterpret(Float32, s | d + y) + reinterpret(Float32, (s | d) + y) end function Float16(val::Float32) @@ -140,7 +140,7 @@ function Float16(val::Float32) t = 0x8000 ⊻ (0x8000 & ((f >> 0x10) % UInt16)) return reinterpret(Float16, t ⊻ ((f >> 0xd) % UInt16)) end - i = (f >> 23) & 0x1ff + 1 + i = ((f >> 23) & 0x1ff) + 1 sh = shifttable[i] f &= 0x007fffff h::UInt16 = basetable[i] + (f >> sh) @@ -150,7 +150,7 @@ function Float16(val::Float32) nextbit = (f >> (sh-1)) & 1 if nextbit != 0 # Round halfway to even or check lower bits - if h&1 == 1 || (f & ((1<<(sh-1))-1)) != 0 + if (h&1) == 1 || (f & ((1<<(sh-1))-1)) != 0 h += 1 end end @@ -209,30 +209,30 @@ const shifttable = Vector{UInt8}(uninitialized, 512) for i = 0:255 e = i - 127 if e < -24 # Very small numbers map to zero - basetable[i|0x000+1] = 0x0000 - basetable[i|0x100+1] = 0x8000 - shifttable[i|0x000+1] = 24 - shifttable[i|0x100+1] = 24 + basetable[(i|0x000)+1] = 0x0000 + basetable[(i|0x100)+1] = 0x8000 + shifttable[(i|0x000)+1] = 24 + shifttable[(i|0x100)+1] = 24 elseif e < -14 # Small numbers map to denorms - basetable[i|0x000+1] = (0x0400>>(-e-14)) - basetable[i|0x100+1] = (0x0400>>(-e-14)) | 0x8000 - shifttable[i|0x000+1] = -e-1 - shifttable[i|0x100+1] = -e-1 + basetable[(i|0x000)+1] = (0x0400>>(-e-14)) + basetable[(i|0x100)+1] = (0x0400>>(-e-14)) | 0x8000 + shifttable[(i|0x000)+1] = -e-1 + shifttable[(i|0x100)+1] = -e-1 elseif e <= 15 # Normal numbers just lose precision - basetable[i|0x000+1] = ((e+15)<<10) - basetable[i|0x100+1] = ((e+15)<<10) | 0x8000 - shifttable[i|0x000+1] = 13 - shifttable[i|0x100+1] = 13 + basetable[(i|0x000)+1] = ((e+15)<<10) + basetable[(i|0x100)+1] = ((e+15)<<10) | 0x8000 + shifttable[(i|0x000)+1] = 13 + shifttable[(i|0x100)+1] = 13 elseif e < 128 # Large numbers map to Infinity - basetable[i|0x000+1] = 0x7C00 - basetable[i|0x100+1] = 0xFC00 - shifttable[i|0x000+1] = 24 - shifttable[i|0x100+1] = 24 + basetable[(i|0x000)+1] = 0x7C00 + basetable[(i|0x100)+1] = 0xFC00 + shifttable[(i|0x000)+1] = 24 + shifttable[(i|0x100)+1] = 24 else # Infinity and NaN's stay Infinity and NaN's - basetable[i|0x000+1] = 0x7C00 - basetable[i|0x100+1] = 0xFC00 - shifttable[i|0x000+1] = 13 - shifttable[i|0x100+1] = 13 + basetable[(i|0x000)+1] = 0x7C00 + basetable[(i|0x100)+1] = 0xFC00 + shifttable[(i|0x000)+1] = 13 + shifttable[(i|0x100)+1] = 13 end end @@ -309,7 +309,7 @@ end function unsafe_trunc(::Type{UInt128}, x::Float64) xu = reinterpret(UInt64,x) - k = Int(xu >> 52) & 0x07ff - 1075 + k = (Int(xu >> 52) & 0x07ff) - 1075 xu = (xu & 0x000f_ffff_ffff_ffff) | 0x0010_0000_0000_0000 if k <= 0 UInt128(xu >> -k) @@ -323,7 +323,7 @@ end function unsafe_trunc(::Type{UInt128}, x::Float32) xu = reinterpret(UInt32,x) - k = Int(xu >> 23) & 0x00ff - 150 + k = (Int(xu >> 23) & 0x00ff) - 150 xu = (xu & 0x007f_ffff) | 0x0080_0000 if k <= 0 UInt128(xu >> -k) @@ -435,10 +435,10 @@ end function ==(x::Float16, y::Float16) ix = reinterpret(UInt16,x) iy = reinterpret(UInt16,y) - if (ix|iy)&0x7fff > 0x7c00 #isnan(x) || isnan(y) + if ((ix|iy)&0x7fff) > 0x7c00 #isnan(x) || isnan(y) return false end - if (ix|iy)&0x7fff == 0x0000 + if ((ix|iy)&0x7fff) == 0x0000 return true end return ix == iy @@ -539,7 +539,7 @@ abs(x::Float64) = abs_float(x) Test whether a floating point number is not a number (NaN). """ isnan(x::AbstractFloat) = x != x -isnan(x::Float16) = reinterpret(UInt16,x)&0x7fff > 0x7c00 +isnan(x::Float16) = (reinterpret(UInt16,x) & 0x7fff) > 0x7c00 isnan(x::Real) = false """ @@ -556,7 +556,7 @@ false ``` """ isfinite(x::AbstractFloat) = x - x == 0 -isfinite(x::Float16) = reinterpret(UInt16,x)&0x7c00 != 0x7c00 +isfinite(x::Float16) = (reinterpret(UInt16,x) & 0x7c00) != 0x7c00 isfinite(x::Real) = decompose(x)[3] != 0 isfinite(x::Integer) = true @@ -718,7 +718,7 @@ Test whether a floating point number is subnormal. """ function issubnormal(x::T) where {T<:IEEEFloat} y = reinterpret(Unsigned, x) - (y & exponent_mask(T) == 0) & (y & significand_mask(T) != 0) + ((y & exponent_mask(T)) == 0) & ((y & significand_mask(T)) != 0) end @eval begin @@ -873,7 +873,7 @@ uinttype(::Type{Float64}) = UInt64 uinttype(::Type{Float32}) = UInt32 uinttype(::Type{Float16}) = UInt16 -Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000 +Base.iszero(x::Float16) = (reinterpret(UInt16, x) & ~sign_mask(Float16)) == 0x0000 ## Array operations on floating point numbers ## diff --git a/base/gmp.jl b/base/gmp.jl index 1acaa6a10e1f6..a706e6fc09711 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -310,7 +310,7 @@ function BigInt(x::Integer) end -rem(x::BigInt, ::Type{Bool}) = !iszero(x) & unsafe_load(x.d) % Bool # never unsafe here +rem(x::BigInt, ::Type{Bool}) = (!iszero(x) & unsafe_load(x.d)) % Bool # never unsafe here rem(x::BigInt, ::Type{T}) where T<:Union{SLimbMax,ULimbMax} = iszero(x) ? zero(T) : flipsign(unsafe_load(x.d) % T, x.size) diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 54a948da473e7..63a40fc5e83cd 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -375,7 +375,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) end zero!(x) shifts::Int = 0 - while base & UInt16(1) == UInt16(0) + while (base & UInt16(1)) == UInt16(0) base >>= UInt16(1) shifts += 1 end diff --git a/base/hashing2.jl b/base/hashing2.jl index 83ef9ea09683f..8011b5c07a52f 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -101,7 +101,7 @@ function decompose(x::Float16)::NTuple{3,Int} isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt16, x) s = (n & 0x03ff) % Int16 - e = (n & 0x7c00 >> 10) % Int + e = ((n & 0x7c00) >> 10) % Int s |= Int16(e != 0) << 10 d = ifelse(signbit(x), -1, 1) s, e - 25 + (e == 0), d @@ -112,7 +112,7 @@ function decompose(x::Float32)::NTuple{3,Int} isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt32, x) s = (n & 0x007fffff) % Int32 - e = (n & 0x7f800000 >> 23) % Int + e = ((n & 0x7f800000) >> 23) % Int s |= Int32(e != 0) << 23 d = ifelse(signbit(x), -1, 1) s, e - 150 + (e == 0), d @@ -123,7 +123,7 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int} isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt64, x) s = (n & 0x000fffffffffffff) % Int64 - e = (n & 0x7ff0000000000000 >> 52) % Int + e = ((n & 0x7ff0000000000000) >> 52) % Int s |= Int64(e != 0) << 52 d = ifelse(signbit(x), -1, 1) s, e - 1075 + (e == 0), d diff --git a/base/inference.jl b/base/inference.jl index 5092d965bcf44..d686f2af9b72f 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -4329,7 +4329,7 @@ function effect_free(@nospecialize(e), src::CodeInfo, mod::Module, allow_volatil elseif isa(e, Symbol) return allow_volatile elseif isa(e, Slot) - return src.slotflags[slot_id(e)] & Slot_UsedUndef == 0 + return (src.slotflags[slot_id(e)] & Slot_UsedUndef) == 0 elseif isa(e, Expr) e = e::Expr head = e.head @@ -5513,7 +5513,7 @@ function void_use_elim_pass!(sv::OptimizationState) # Explicitly listed here for clarity return false elseif isa(ex, Slot) - return sv.src.slotflags[slot_id(ex)] & Slot_UsedUndef != 0 + return (sv.src.slotflags[slot_id(ex)] & Slot_UsedUndef) != 0 elseif isa(ex, GlobalRef) ex = ex::GlobalRef return !isdefined(ex.mod, ex.name) @@ -5761,7 +5761,7 @@ end function get_undef_flag_slot(src::CodeInfo, flagslots, id) flag_id = flagslots[id] flag_id != 0 && return SlotNumber(flag_id) - slot = add_slot!(src, Nothing, src.slotflags[id] & Slot_AssignedOnce != 0, src.slotnames[id]) + slot = add_slot!(src, Nothing, (src.slotflags[id] & Slot_AssignedOnce) != 0, src.slotnames[id]) flag_id = slot_id(slot) src.slotflags[flag_id] |= Slot_StaticUndef | Slot_UsedUndef flagslots[id] = flag_id @@ -5991,20 +5991,20 @@ add_use(infomap::ValueInfoMap, var, use::ValueUse) = add_use(infomap[var], use) ssa && return false flags = src.slotflags[id] # The check for `UsedUndef` shouldn't be necessary but doesn't hurt - return flags & Slot_UsedUndef != 0 || flags & Slot_StaticUndef != 0 + return (flags & Slot_UsedUndef) != 0 || (flags & Slot_StaticUndef) != 0 end @inline function var_has_undef(src, id, ssa=false) ssa && return false flags = src.slotflags[id] - return flags & Slot_UsedUndef != 0 + return (flags & Slot_UsedUndef) != 0 end @inline function var_is_ssa(src, id, ssa=false) ssa && return true flags = src.slotflags[id] # The check for `UsedUndef` shouldn't be necessary but doesn't hurt - return flags & (Slot_UsedUndef | Slot_StaticUndef) == 0 && flags & Slot_AssignedOnce != 0 + return (flags & (Slot_UsedUndef | Slot_StaticUndef)) == 0 && (flags & Slot_AssignedOnce) != 0 end function scan_expr_use!(infomap, body, i, ex, src) @@ -7429,7 +7429,7 @@ function verify_value_infomap(ctx::AllocOptContext) @check_ast(ctx, assign.args[1] === slotv) end end - if ctx.sv.src.slotflags[i] & Slot_AssignedOnce != 0 + if (ctx.sv.src.slotflags[i] & Slot_AssignedOnce) != 0 @check_ast(ctx, ndef <= 1) end for use in info.uses diff --git a/base/int.jl b/base/int.jl index fbe352b343ad9..ec85fb58bf667 100644 --- a/base/int.jl +++ b/base/int.jl @@ -657,7 +657,7 @@ if Core.sizeof(Int) == 4 w2 = reinterpret(Int64, t) >> 32 w1 = u0 * reinterpret(UInt64, v1) + (t & 0xffffffff) hi = u1 * v1 + w2 + (reinterpret(Int64, w1) >> 32) - lo = w0 & 0xffffffff + (w1 << 32) + lo = (w0 & 0xffffffff) + (w1 << 32) return Int128(hi) << 64 + Int128(lo) end @@ -672,7 +672,7 @@ if Core.sizeof(Int) == 4 w2 = t >>> 32 w1 = u0 * v1 + (t & 0xffffffff) hi = u1 * v1 + w2 + (w1 >>> 32) - lo = w0 & 0xffffffff + (w1 << 32) + lo = (w0 & 0xffffffff) + (w1 << 32) return UInt128(hi) << 64 + UInt128(lo) end diff --git a/base/io.jl b/base/io.jl index ae71210cb1336..d34c375adbb8c 100644 --- a/base/io.jl +++ b/base/io.jl @@ -605,7 +605,7 @@ function read(io::IO, ::Type{Char}) if l < 24 s = 16 while s ≥ l && !eof(io) - peek(io) & 0xc0 == 0x80 || break + (peek(io) & 0xc0) == 0x80 || break b = read(io, UInt8) c |= UInt32(b) << s s -= 8 diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index f692005ef8de5..7b8dacde6b5a1 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -44,7 +44,7 @@ const VERSION = version() Test whether the bits of `val` indexed by `flag` are set (`1`) or unset (`0`). """ -isset(val::Integer, flag::Integer) = (val & flag == flag) +isset(val::Integer, flag::Integer) = ((val & flag) == flag) """ reset(val::Integer, flag::Integer) diff --git a/base/math.jl b/base/math.jl index 5c14f49624338..7b44d9c877fa8 100644 --- a/base/math.jl +++ b/base/math.jl @@ -308,11 +308,11 @@ end elseif x <= -1023 # if -1073 < x <= -1023 then Result will be a subnormal number # Hex literal with padding must be used to work on 32bit machine - reinterpret(Float64, 0x0000_0000_0000_0001 << ((x + 1074)) % UInt) + reinterpret(Float64, 0x0000_0000_0000_0001 << (((x + 1074)) % UInt)) else # We will cast everything to Int64 to avoid errors in case of Int128 # If x is a Int128, and is outside the range of Int64, then it is not -1023 0 @@ -847,7 +847,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) end end else - if n & 2 == 2 # n % 4 == 3: add 3pi/2 + if (n & 2) == 2 # n % 4 == 3: add 3pi/2 z = add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 z = add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -867,7 +867,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: add pi + if (n & 2) == 2 # n % 4 == 2: add pi return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else # n % 4 == 0: add 0 or 2pi if y.hi > 0 @@ -877,7 +877,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) end end else - if n & 2 == 2 # n % 4 == 3: add 3pi/2 + if (n & 2) == 2 # n % 4 == 3: add 3pi/2 return add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -896,7 +896,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: sub pi + if (n & 2) == 2 # n % 4 == 2: sub pi return add22condh(y.hi,y.lo,-pi2o2_h,-pi2o2_l) else # n % 4 == 0: sub 0 or 2pi if y.hi < 0 @@ -906,7 +906,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) end end else - if n & 2 == 2 # n % 4 == 3: sub pi/2 + if (n & 2) == 2 # n % 4 == 3: sub pi/2 return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l) else # n % 4 == 1: sub 3pi/2 return add22condh(y.hi,y.lo,-pi3o2_h,-pi3o2_l) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index d42af46fe019c..4b8a386770ee6 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -564,7 +564,7 @@ done(L::LogicalIndex, s) = s[3] > length(L) i, n = s Bc = L.mask.chunks while true - if Bc[_div64(i)+1] & (UInt64(1)<<_mod64(i)) != 0 + if (Bc[_div64(i)+1] & (UInt64(1)<<_mod64(i))) != 0 i += 1 return (i, (i, n+1)) end diff --git a/base/process.jl b/base/process.jl index aec5045839af4..ee50acd285153 100644 --- a/base/process.jl +++ b/base/process.jl @@ -19,9 +19,9 @@ struct Cmd <: AbstractCmd new(cmd.exec, ignorestatus, flags, env, dir === cmd.dir ? dir : cstr(dir)) function Cmd(cmd::Cmd; ignorestatus::Bool=cmd.ignorestatus, env=cmd.env, dir::AbstractString=cmd.dir, - detach::Bool = 0 != cmd.flags & UV_PROCESS_DETACHED, - windows_verbatim::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS, - windows_hide::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_HIDE) + detach::Bool = 0 != (cmd.flags & UV_PROCESS_DETACHED), + windows_verbatim::Bool = 0 != (cmd.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS), + windows_hide::Bool = 0 != (cmd.flags & UV_PROCESS_WINDOWS_HIDE)) flags = detach*UV_PROCESS_DETACHED | windows_verbatim*UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS | windows_hide*UV_PROCESS_WINDOWS_HIDE diff --git a/base/random/generation.jl b/base/random/generation.jl index 363d09817699e..52208cc9939b1 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -196,7 +196,7 @@ function SamplerRangeFast(r::AbstractUnitRange{T}, ::Type{U}) where {T,U} isempty(r) && throw(ArgumentError("range must be non-empty")) m = (last(r) - first(r)) % unsigned(T) % U # % unsigned(T) to not propagate sign bit bw = (sizeof(U) << 3 - leading_zeros(m)) % UInt # bit-width - mask = (1 % U << bw) - (1 % U) + mask = ((1 % U) << bw) - (1 % U) SamplerRangeFast{U,T}(first(r), bw, m, mask) end diff --git a/base/reflection.jl b/base/reflection.jl index bf59703fea6c6..ea93bf5304158 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -251,10 +251,10 @@ datatype_alignment(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) Int(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment & 0x1FF) datatype_haspadding(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9) & 1 == 1 + ((unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9) & 1) == 1 datatype_pointerfree(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10) & 0xFFFFF == 0 + ((unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10) & 0xFFFFF) == 0 datatype_fielddesc_type(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30) & 3 diff --git a/base/show.jl b/base/show.jl index 25d79b5095680..0ec9cc275578d 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1089,7 +1089,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) show_unquoted(io, args[1], indent) # comparison (i.e. "x < y < z") - elseif head === :comparison && nargs >= 3 && (nargs&1==1) + elseif head === :comparison && nargs >= 3 && isodd(nargs) comp_prec = minimum(operator_precedence, args[2:2:end]) if comp_prec <= prec show_enclosed_list(io, '(', args, " ", ')', indent, comp_prec) @@ -1860,7 +1860,7 @@ function print_bit_chunk(io::IO, c::UInt64, l::Integer = 64) for s = 0:l-1 d = (c >>> s) & 1 print(io, "01"[d + 1]) - if (s + 1) & 7 == 0 + if ((s + 1) & 7) == 0 print(io, " ") end end diff --git a/base/socket.jl b/base/socket.jl index 5e061f305aeb5..2b932cec58397 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -105,7 +105,7 @@ function ipv6_field(ip::IPv6,i) if i < 0 || i > 7 throw(BoundsError()) end - UInt16(ip.host&(UInt128(0xFFFF)<<(i*16))>>(i*16)) + UInt16((ip.host&(UInt128(0xFFFF)<<(i*16)))>>(i*16)) end show(io::IO, ip::IPv6) = print(io,"ip\"",ip,"\"") @@ -526,7 +526,7 @@ function uv_recvcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}, addr::P if nread < 0 Libc.free(buf_addr) notify_error(sock.recvnotify, UVError("recv", nread)) - elseif flags & UV_UDP_PARTIAL > 0 + elseif (flags & UV_UDP_PARTIAL) > 0 Libc.free(buf_addr) notify_error(sock.recvnotify, "Partial message received") else diff --git a/base/special/exp.jl b/base/special/exp.jl index ccabe295597db..5bd34b8366c0d 100644 --- a/base/special/exp.jl +++ b/base/special/exp.jl @@ -76,7 +76,7 @@ function exp(x::T) where T<:Union{Float32,Float64} # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP(T)) if xa >= exponent_mask(T) - xa & significand_mask(T) != 0 && return T(NaN) + (xa & significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp(+-Inf) end x > MAX_EXP(T) && return T(Inf) diff --git a/base/special/exp10.jl b/base/special/exp10.jl index 711da3b04549b..63dac4f1bd00e 100644 --- a/base/special/exp10.jl +++ b/base/special/exp10.jl @@ -88,7 +88,7 @@ function exp10(x::T) where T<:Union{Float32,Float64} # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP10(T)) if xa >= exponent_mask(T) - xa & significand_mask(T) != 0 && return T(NaN) + (xa & significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp10(+-Inf) end x > MAX_EXP10(T) && return T(Inf) diff --git a/base/special/log.jl b/base/special/log.jl index e62ddf541705e..371257090e4a4 100644 --- a/base/special/log.jl +++ b/base/special/log.jl @@ -266,7 +266,7 @@ function log(x::Float64) if m == 0 # x is subnormal x *= 1.8014398509481984e16 # 0x1p54, normalise significand xu = reinterpret(UInt64,x) - m = Int(xu >> 52) & 0x07ff - 54 + m = (Int(xu >> 52) & 0x07ff) - 54 end m -= 1023 y = reinterpret(Float64,(xu & 0x000f_ffff_ffff_ffff) | 0x3ff0_0000_0000_0000) @@ -302,7 +302,7 @@ function log(x::Float32) if m == 0 # x is subnormal x *= 3.3554432f7 # 0x1p25, normalise significand xu = reinterpret(UInt32,x) - m = Int(xu >> 23) & 0x00ff - 25 + m = (Int(xu >> 23) & 0x00ff) - 25 end m -= 127 y = reinterpret(Float32,(xu & 0x007f_ffff) | 0x3f80_0000) @@ -338,7 +338,7 @@ function log1p(x::Float64) z = 1.0 + x zu = reinterpret(UInt64,z) s = reinterpret(Float64,0x7fe0_0000_0000_0000 - (zu & 0xfff0_0000_0000_0000)) # 2^-m - m = Int(zu >> 52) & 0x07ff - 1023 # z cannot be subnormal + m = (Int(zu >> 52) & 0x07ff) - 1023 # z cannot be subnormal c = m > 0 ? 1.0-(z-x) : x-(z-1.0) # 1+x = z+c exactly y = reinterpret(Float64,(zu & 0x000f_ffff_ffff_ffff) | 0x3ff0_0000_0000_0000) @@ -371,7 +371,7 @@ function log1p(x::Float32) z = 1f0 + x zu = reinterpret(UInt32,z) s = reinterpret(Float32,0x7f000000 - (zu & 0xff80_0000)) # 2^-m - m = Int(zu >> 23) & 0x00ff - 127 # z cannot be subnormal + m = (Int(zu >> 23) & 0x00ff) - 127 # z cannot be subnormal c = m > 0 ? 1f0-(z-x) : x-(z-1f0) # 1+x = z+c y = reinterpret(Float32,(zu & 0x007f_ffff) | 0x3f80_0000) diff --git a/base/stat.jl b/base/stat.jl index 4e475d9d0f2c8..5d1b12052cff8 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -151,21 +151,21 @@ Equivalent to `stat(file).ctime` Returns `true` if `path` is a valid filesystem path, `false` otherwise. """ - ispath(st::StatStruct) = filemode(st) & 0xf000 != 0x0000 + ispath(st::StatStruct) = (filemode(st) & 0xf000) != 0x0000 """ isfifo(path) -> Bool Returns `true` if `path` is a FIFO, `false` otherwise. """ - isfifo(st::StatStruct) = filemode(st) & 0xf000 == 0x1000 + isfifo(st::StatStruct) = (filemode(st) & 0xf000) == 0x1000 """ ischardev(path) -> Bool Returns `true` if `path` is a character device, `false` otherwise. """ -ischardev(st::StatStruct) = filemode(st) & 0xf000 == 0x2000 +ischardev(st::StatStruct) = (filemode(st) & 0xf000) == 0x2000 """ isdir(path) -> Bool @@ -186,14 +186,14 @@ false julia> close(f) ``` """ - isdir(st::StatStruct) = filemode(st) & 0xf000 == 0x4000 + isdir(st::StatStruct) = (filemode(st) & 0xf000) == 0x4000 """ isblockdev(path) -> Bool Returns `true` if `path` is a block device, `false` otherwise. """ -isblockdev(st::StatStruct) = filemode(st) & 0xf000 == 0x6000 +isblockdev(st::StatStruct) = (filemode(st) & 0xf000) == 0x6000 """ isfile(path) -> Bool @@ -213,21 +213,21 @@ true julia> close(f) ``` """ - isfile(st::StatStruct) = filemode(st) & 0xf000 == 0x8000 + isfile(st::StatStruct) = (filemode(st) & 0xf000) == 0x8000 """ islink(path) -> Bool Returns `true` if `path` is a symbolic link, `false` otherwise. """ - islink(st::StatStruct) = filemode(st) & 0xf000 == 0xa000 + islink(st::StatStruct) = (filemode(st) & 0xf000) == 0xa000 """ issocket(path) -> Bool Returns `true` if `path` is a socket, `false` otherwise. """ - issocket(st::StatStruct) = filemode(st) & 0xf000 == 0xc000 + issocket(st::StatStruct) = (filemode(st) & 0xf000) == 0xc000 # mode permission predicates diff --git a/base/strings/search.jl b/base/strings/search.jl index abd32d6183dc4..822688067e86e 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -194,13 +194,13 @@ function _searchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, i) end # no match, try to rule out the next character - if i < w && bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1)) == 0 + if i < w && (bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n else i += skip end elseif i < w - if bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1)) == 0 + if (bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n end end @@ -361,13 +361,13 @@ function _rsearchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, k end # no match, try to rule out the next character - if i > 1 && bloom_mask & _search_bloom_mask(_nthbyte(s,i-1)) == 0 + if i > 1 && (bloom_mask & _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n else i -= skip end elseif i > 1 - if bloom_mask & _search_bloom_mask(_nthbyte(s,i-1)) == 0 + if (bloom_mask & _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n end end diff --git a/base/strings/string.jl b/base/strings/string.jl index 888cda75c6046..46f78523bf540 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -99,13 +99,13 @@ function thisind(s::String, i::Int) i == n + 1 && return i @boundscheck between(i, 0, n) || throw(BoundsError(s, i)) @inbounds b = codeunit(s, i) - b & 0xc0 == 0x80 || return i + (b & 0xc0) == 0x80 || return i @inbounds b = codeunit(s, i-1) between(b, 0b11000000, 0b11110111) && return i-1 - (b & 0xc0 == 0x80) & (i-2 > 0) || return i + ((b & 0xc0) == 0x80) & (i-2 > 0) || return i @inbounds b = codeunit(s, i-2) between(b, 0b11100000, 0b11110111) && return i-2 - (b & 0xc0 == 0x80) & (i-3 > 0) || return i + ((b & 0xc0) == 0x80) & (i-3 > 0) || return i @inbounds b = codeunit(s, i-3) between(b, 0b11110000, 0b11110111) && return i-3 return i @@ -123,15 +123,15 @@ function nextind(s::String, i::Int) end # first continuation byte @inbounds b = codeunit(s, i += 1) - b & 0xc0 ≠ 0x80 && return i + (b & 0xc0) ≠ 0x80 && return i ((i += 1) > n) | (l < 0xe0) && return i # second continuation byte @inbounds b = codeunit(s, i) - b & 0xc0 ≠ 0x80 && return i + (b & 0xc0) ≠ 0x80 && return i ((i += 1) > n) | (l < 0xf0) && return i # third continuation byte @inbounds b = codeunit(s, i) - ifelse(b & 0xc0 ≠ 0x80, i, i+1) + ifelse((b & 0xc0) ≠ 0x80, i, i+1) end ## checking UTF-8 & ACSII validity ## @@ -147,7 +147,7 @@ byte_string_classify(s::String) = isvalid(::Type{String}, s::Union{Vector{UInt8},String}) = byte_string_classify(s) ≠ 0 isvalid(s::String) = isvalid(String, s) -is_valid_continuation(c) = c & 0xc0 == 0x80 +is_valid_continuation(c) = (c & 0xc0) == 0x80 ## required core functionality ## @@ -164,17 +164,17 @@ function next_continued(s::String, i::Int, u::UInt32) # first continuation byte (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b) << 16 # second continuation byte ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b) << 8 # third continuation byte ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b); i += 1 @label ret return reinterpret(Char, u), i @@ -197,17 +197,17 @@ function getindex_continued(s::String, i::Int, u::UInt32) (i += 1) > n && @goto ret @inbounds b = codeunit(s, i) # cont byte 1 - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b) << 16 ((i += 1) > n) | (u < 0xe0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 2 - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b) << 8 ((i += 1) > n) | (u < 0xf0000000) && @goto ret @inbounds b = codeunit(s, i) # cont byte 3 - b & 0xc0 == 0x80 || @goto ret + (b & 0xc0) == 0x80 || @goto ret u |= UInt32(b) @label ret return reinterpret(Char, u) @@ -258,17 +258,17 @@ length(s::String) = _length(s, 1, ncodeunits(s), ncodeunits(s)) end l = b b = codeunit(s, i) # cont byte 1 - c -= (x = b & 0xc0 == 0x80) + c -= (x = (b & 0xc0) == 0x80) x & (l ≥ 0xe0) || continue (i += 1) ≤ n || return c b = codeunit(s, i) # cont byte 2 - c -= (x = b & 0xc0 == 0x80) + c -= (x = (b & 0xc0) == 0x80) x & (l ≥ 0xf0) || continue (i += 1) ≤ n || return c b = codeunit(s, i) # cont byte 3 - c -= (b & 0xc0 == 0x80) + c -= ((b & 0xc0) == 0x80) end end diff --git a/base/strings/util.jl b/base/strings/util.jl index 65b1a3a6a003b..7fa80da5058d6 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -527,7 +527,7 @@ function bytes2hex(a::AbstractArray{UInt8}) i = 0 for x in a b[i += 1] = hex_chars[1 + x >> 4] - b[i += 1] = hex_chars[1 + x & 0xf] + b[i += 1] = hex_chars[1 + (x & 0xf)] end return String(b) end diff --git a/base/util.jl b/base/util.jl index a9ee3754f751d..45a5266f605be 100644 --- a/base/util.jl +++ b/base/util.jl @@ -677,7 +677,7 @@ function _check_bitarray_consistency(B::BitArray{N}) where N nc = length(Bc) nc == num_bit_chunks(n) || (@warn("Incorrect chunks length for length $n: expected=$(num_bit_chunks(n)) actual=$nc"); return false) n == 0 && return true - Bc[end] & _msk_end(n) == Bc[end] || (@warn("Nonzero bits in chunk after `BitArray` end"); return false) + (Bc[end] & _msk_end(n)) == Bc[end] || (@warn("Nonzero bits in chunk after `BitArray` end"); return false) return true end diff --git a/src/julia-parser.scm b/src/julia-parser.scm index add497ff2f046..514c99c58119a 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -807,27 +807,47 @@ (define (parse-and s) (parse-RtoL s parse-comparison is-prec-lazy-and? #t parse-and)) (define (parse-comparison s) - (let loop ((ex (parse-pipe< s)) + (let loop ((ex (parse-pipe< s)) (first #t)) (let ((t (peek-token s))) (cond ((is-prec-comparison? t) (begin (take-token s) (if first - (loop (list 'comparison ex t (parse-pipe< s)) #f) - (loop (append ex (list t (parse-pipe< s))) #f)))) - (first ex) - ((length= ex 4) + (loop (cons (list 'comparison (dep-check s ex t) t (dep-check s (parse-pipe< s) t)) + #f) + #f) + (loop (cons (append (car ex) (list t (dep-check s (parse-pipe< s) t))) + #f) + #f)))) + (first (car ex)) + ((length= (car ex) 4) ;; only a single comparison; special chained syntax not required - (let ((op (caddr ex)) - (arg1 (cadr ex)) - (arg2 (cadddr ex))) + (let ((op (caddr (car ex))) + (arg1 (cadr (car ex))) + (arg2 (cadddr (car ex)))) (if (or (eq? op '|<:|) (eq? op '|>:|)) `(,op ,arg1 ,arg2) `(call ,op ,arg1 ,arg2)))) - (else ex))))) + (else (car ex)))))) + +(define (parse-pipe< s) ;;(parse-RtoL s parse-pipe> is-prec-pipe s)) + (t (peek-token s))) + (if (is-prec-pipe is-prec-pipe s) (parse-LtoR s parse-range is-prec-pipe>?)) +(define (parse-pipe> s) ;;(parse-LtoR s parse-range is-prec-pipe>?)) + (let loop ((ex (parse-range s)) + (t (peek-token s))) + (if (is-prec-pipe>? t) + (begin (take-token s) + (loop (cons (list 'call t (dep-check s ex t) (dep-check s (parse-range s) t)) + #f) + (peek-token s))) + ex))) ; parse ranges and postfix ... ; colon is strange; 3 arguments with 2 colons yields one call: @@ -843,38 +863,42 @@ ; we will leave : expressions as a syntax form, not a call to ':', ; so they can be processed by syntax passes. (define (parse-range s) - (let loop ((ex (parse-expr s)) + (let loop ((ex (parse-expr s)) (first? #t)) (let* ((t (peek-token s)) (spc (ts:space? s))) (cond ((and first? (eq? t '|..|)) (take-token s) - `(call ,t ,ex ,(parse-expr s))) + (cons `(call ,t ,(dep-check s ex '|..|) ,(dep-check s (parse-expr s) '|..|)) + #f)) ((and range-colon-enabled (eq? t ':)) (take-token s) (if (and space-sensitive spc (or (peek-token s) #t) (not (ts:space? s))) ;; "a :b" in space sensitive mode (begin (ts:put-back! s ': spc) - ex) + (cons (car ex) #f)) (let ((argument (cond ((closing-token? (peek-token s)) (error (string "missing last argument in \"" - (deparse ex) ":\" range expression "))) + (deparse (car ex)) ":\" range expression "))) ((newline? (peek-token s)) (error "line break in \":\" expression")) (else - (parse-expr s))))) + (dep-check s (parse-expr s) t))))) (if (and (not (ts:space? s)) (or (eq? argument '<) (eq? argument '>))) (error (string "\":" argument "\" found instead of \"" argument ":\""))) (if first? - (loop (list t ex argument) #f) - (loop (append ex (list argument)) #t))))) + (loop (cons (list t (dep-check s ex t) argument) #f) + #f) + (loop (cons (append (car ex) (list argument)) #f) + #t))))) ((eq? t '...) (take-token s) - (list '... ex)) + (cons (list '... (dep-check s ex '...)) + #f)) (else ex))))) ;; parse left to right chains of a certain binary operator @@ -897,66 +921,63 @@ ;; parse left to right, combining chains of a certain operator into 1 call ;; e.g. a+b+c => (call + a b c) (define (parse-with-chains s down ops chain-ops) - (let loop ((ex (down s))) - (let ((t (peek-token s))) - (if (not (ops t)) - ex - (let ((spc (ts:space? s))) - (take-token s) - (cond ((and space-sensitive spc (memq t unary-and-binary-ops) - (not (eqv? (peek-char (ts:port s)) #\ ))) - ;; here we have "x -y" - (ts:put-back! s t spc) - ex) - ((memq t chain-ops) - (loop (list* 'call t ex - (parse-chain s down t)))) - (else - (loop (list 'call t ex (down s)))))))))) - -(define (parse-with-chains-warn s down ops chain-ops) - (let loop ((ex (down s)) - (got #f)) + (let loop ((p-ex (down s))) (let ((t (peek-token s))) (if (not (ops t)) - (cons ex got) + p-ex (let ((spc (ts:space? s))) (take-token s) (cond ((and space-sensitive spc (memq t unary-and-binary-ops) (not (eqv? (peek-char (ts:port s)) #\ ))) ;; here we have "x -y" (ts:put-back! s t spc) - (cons ex got)) + p-ex) ((memq t chain-ops) - (loop (list* 'call t ex - (parse-chain s down t)) - #t)) + (loop (cons (list* 'call t (dep-check s p-ex t) + (parse-chain s (lambda (s) (dep-check s (down s) t)) t)) + t))) (else - (loop (list 'call t ex (down s)) - got)))))))) + (loop (cons (list 'call t (dep-check s p-ex t) (dep-check s (down s) t)) + t))))))))) (define (parse-expr s) (parse-with-chains s parse-shift is-prec-plus? '(+ ++))) -(define (bitshift-warn s) - (syntax-deprecation s (string "call to `*` inside call to bitshift operator") - "parenthesized call to `*`")) +(define (deprecated-precedence s inner outer) + (syntax-deprecation s (string "call to `" inner "` inside call to `" outer "`") + (string "parenthesized call to `" inner "`"))) + +;; check whether the relative precedence of (cdr p) and op is deprecated, and warn if so +;; returns (car p), which is the parsed subexpression. +(define (dep-check s p op) + (let ((ex (car p)) + (inner (cdr p))) + (if (and inner + (not (eq? inner op)) + (or (and (memq inner '(& |\||)) + (not (memq op '(& |\||)))) + (and (eq? inner '*) + (is-prec-bitshift? op)))) + (deprecated-precedence s inner op)) + ex)) (define (parse-shift s) #;(parse-LtoR s parse-term is-prec-bitshift?) - (let loop ((ex (parse-term s)) + (let loop ((p-ex (parse-term s)) (t (peek-token s)) (warn1 #f)) - (let ((ex (car ex)) - (warn (cdr ex))) + (let ((ex (car p-ex)) + (warn (cdr p-ex))) (if (is-prec-bitshift? t) - (begin (if warn (bitshift-warn s)) + (begin (if warn (deprecated-precedence s warn t)) (take-token s) (let ((nxt (parse-term s))) - (loop (cons (list 'call t ex (car nxt)) (cdr nxt)) (peek-token s) (cdr nxt)))) - (begin (if warn1 (bitshift-warn s)) - ex))))) + (loop (cons (list 'call t ex (car nxt)) (cdr nxt)) + (peek-token s) + (cdr nxt)))) + (begin (if warn1 (deprecated-precedence s warn1 (cadr ex))) + p-ex))))) -(define (parse-term s) (parse-with-chains-warn s parse-rational is-prec-times? '(*))) -(define (parse-rational s) (parse-LtoR s parse-unary-subtype is-prec-rational?)) +(define (parse-term s) (parse-with-chains s parse-rational is-prec-times? '(*))) +(define (parse-rational s) (cons (parse-LtoR s parse-unary-subtype is-prec-rational?) #f)) ;; parse `<: A where B` as `<: (A where B)` (issue #21545) (define (parse-unary-subtype s) @@ -1585,7 +1606,7 @@ (without-whitespace-newline (let ((doargs (if (memv (peek-token s) '(#\newline #\;)) '() - (parse-comma-separated s parse-range)))) + (parse-comma-separated s (lambda (s) (car (parse-range s))))))) `(-> (tuple ,@doargs) ,(begin0 (parse-block s) (expect-end s 'do))))))) @@ -1676,11 +1697,11 @@ #f) #t))) #f)) - (lhs (parse-pipe< s)) + (lhs (car (parse-pipe< s))) (t (peek-token s))) (cond ((memq t '(= in ∈)) (take-token s) - (let* ((rhs (parse-pipe< s)) + (let* ((rhs (dep-check s (parse-pipe< s) t)) (t (peek-token s))) #;(if (not (or (closing-token? t) (newline? t))) ;; should be: (error "invalid iteration specification") diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 1b3576e3aebdb..21618ba72024c 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -71,7 +71,7 @@ function settings(s::Int, shared::Bool) systemerror("fcntl F_GETFL", mode == -1) mode = mode & 3 prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : PROT_READ | PROT_WRITE - if prot & PROT_READ == 0 + if (prot & PROT_READ) == 0 throw(ArgumentError("mmap requires read permissions on the file (open with \"r+\" mode to override)")) end end @@ -297,7 +297,7 @@ function mmap(io::IOStream, ::Type{<:BitArray}, dims::NTuple{N,Integer}, if !isreadonly(io) chunks[end] &= Base._msk_end(n) else - if chunks[end] != chunks[end] & Base._msk_end(n) + if chunks[end] != (chunks[end] & Base._msk_end(n)) throw(ArgumentError("the given file does not contain a valid BitArray of size $(join(dims, 'x')) (open with \"r+\" mode to override)")) end end diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index a7ddfd4cc4daf..26d3040a61a71 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -232,7 +232,7 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode) kws[1] = Symbol("(", kws[1]) kws[end] = Symbol(kws[end], ")") quoted = Expr(:comparison, args[1], func_sym, args[2], kws...) - if length(quoted.args) & 1 == 0 # hack to fit `show_unquoted` + if iseven(length(quoted.args)) # hack to fit `show_unquoted` push!(quoted.args, Symbol()) end else diff --git a/test/int.jl b/test/int.jl index ba4c998bdc4bb..808a79dd0f329 100644 --- a/test/int.jl +++ b/test/int.jl @@ -227,8 +227,8 @@ end @test 0x00007ffea27edaa0 + (-40) === (-40) + 0x00007ffea27edaa0 === 0x00007ffea27eda78 @test UInt64(1) * Int64(-1) === typemax(UInt64) @test UInt(1) - (-1) == 2 -@test UInt64(15) & -4 === UInt64(12) -@test UInt64(15) | -4 === typemax(UInt64) +@test (UInt64(15) & -4) === UInt64(12) +@test (UInt64(15) | -4) === typemax(UInt64) @test UInt64(15) ⊻ -4 === 0xfffffffffffffff3 diff --git a/test/numbers.jl b/test/numbers.jl index 831398f443d31..f55bc38d629ca 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -22,15 +22,15 @@ const ≣ = isequal # convenient for comparing NaNs @test ~true == false @test ~false == true - @test false & false == false - @test true & false == false - @test false & true == false - @test true & true == true + @test (false & false) == false + @test (true & false) == false + @test (false & true) == false + @test (true & true) == true - @test false | false == false - @test true | false == true - @test false | true == true - @test true | true == true + @test (false | false) == false + @test (true | false) == true + @test (false | true) == true + @test (true | true) == true @test false ⊻ false == false @test true ⊻ false == true @@ -833,9 +833,9 @@ end @test (-x==-y)==(-y==-x) @test (-x!=-y)==!(-x==-y) - @test (x