diff --git a/NEWS.md b/NEWS.md index 1c356a33be8b5..d9c0de633fca7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -150,11 +150,13 @@ Deprecated or removed and the Base signal processing functions which used FFTs are now in DSP.jl ([#21956]). * The `corrected` positional argument to `cov` has been deprecated in favor of - a keyword argument with the same name (#21709). + a keyword argument with the same name ([#21709]). - * Omitting a space between the condition and `?` in a ternary expression has been deprecated. + * Omitting spaces around the `?` and the `:` tokens in a ternary expression has been deprecated. Ternaries must now include some amount of whitespace, e.g. `x ? a : b` rather than - `x? a : b` ([#22523]). + `x?a:b` ([#22523] and [#22712]). + + * `?` can no longer be used as an identifier name ([#22712]) * The method `replace(s::AbstractString, pat, r, count)` with `count <= 0` is deprecated in favor of `replace(s::AbstractString, pat, r, typemax(Int))` ([#22325]). @@ -994,4 +996,6 @@ Command-line option changes [#22310]: https://github.com/JuliaLang/julia/issues/22310 [#22523]: https://github.com/JuliaLang/julia/issues/22523 [#22532]: https://github.com/JuliaLang/julia/issues/22532 +[#22709]: https://github.com/JuliaLang/julia/issues/22709 +[#22712]: https://github.com/JuliaLang/julia/issues/22712 [#22732]: https://github.com/JuliaLang/julia/issues/22732 diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 1dcd95a8a6870..783c959340391 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -250,7 +250,7 @@ the byte representation is different. This would create a 25-by-30000 `BitArray`, linked to the file associated with stream `s`. """ -Mmap.mmap(io, ::BitArray, dims = ?, offset = ?) +Mmap.mmap(io, ::BitArray, dims, offset) """ sizeof(T) @@ -2151,7 +2151,7 @@ julia> pop!(d, "e", 4) 4 ``` """ -pop!(collection,key,?) +pop!(collection,key,default) """ pop!(collection) -> item diff --git a/base/grisu/bignum.jl b/base/grisu/bignum.jl index 734dbefca1f1a..2f1d67ce292ed 100644 --- a/base/grisu/bignum.jl +++ b/base/grisu/bignum.jl @@ -79,7 +79,7 @@ function generateshortestdigits!(num,den,minus,plus,is_even,buffer) in_delta_room_minus = is_even ? Bignums.lessequal(num,minus) : Bignums.less(num,minus) in_delta_room_plus = is_even ? - Bignums.pluscompare(num,plus,den) >= 0: Bignums.pluscompare(num,plus,den) > 0 + Bignums.pluscompare(num,plus,den) >= 0 : Bignums.pluscompare(num,plus,den) > 0 if !in_delta_room_minus && !in_delta_room_plus Bignums.times10!(num) Bignums.times10!(minus) diff --git a/base/libgit2/repository.jl b/base/libgit2/repository.jl index 3cf3295c55f90..84e7c70681665 100644 --- a/base/libgit2/repository.jl +++ b/base/libgit2/repository.jl @@ -351,7 +351,7 @@ function reset!(repo::GitRepo, obj::Nullable{<:GitObject}, pathspecs::AbstractSt @check ccall((:git_reset_default, :libgit2), Cint, (Ptr{Void}, Ptr{Void}, Ptr{StrArrayStruct}), repo.ptr, - isnull(obj) ? C_NULL: Base.get(obj).ptr, + isnull(obj) ? C_NULL : Base.get(obj).ptr, collect(pathspecs)) return head_oid(repo) end diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 0fce02cbb699f..553ec886a3933 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -372,7 +372,7 @@ end # blas.jl defines matmul for floats; other integer and mixed precision # cases are handled here -lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1:2), size(M, t=='N' ? 2:1)) +lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1 : 2), size(M, t=='N' ? 2 : 1)) function copy!(B::AbstractVecOrMat, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat, ir_src::UnitRange{Int}, jr_src::UnitRange{Int}) if tM == 'N' diff --git a/base/linalg/special.jl b/base/linalg/special.jl index d57ff0f23520a..e7ba87788d40b 100644 --- a/base/linalg/special.jl +++ b/base/linalg/special.jl @@ -26,7 +26,7 @@ end convert(::Type{Tridiagonal}, A::Bidiagonal{T}) where {T} = Tridiagonal(A.uplo == 'U' ? zeros(T, size(A.dv,1)-1) : A.ev, A.dv, - A.uplo == 'U' ? A.ev:zeros(T, size(A.dv,1)-1)) + A.uplo == 'U' ? A.ev : zeros(T, size(A.dv,1)-1)) function convert(::Type{Bidiagonal}, A::SymTridiagonal) if !iszero(A.ev) diff --git a/base/parse.jl b/base/parse.jl index 03d460d0585b8..543429ce142d9 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -223,7 +223,7 @@ function parse(str::AbstractString, pos::Int; greedy::Bool=true, raise::Bool=tru bstr = String(str) ex, pos = ccall(:jl_parse_string, Any, (Ptr{UInt8}, Csize_t, Int32, Int32), - bstr, sizeof(bstr), pos-1, greedy ? 1:0) + bstr, sizeof(bstr), pos-1, greedy ? 1 : 0) if raise && isa(ex,Expr) && ex.head === :error throw(ParseError(ex.args[1])) end diff --git a/base/version.jl b/base/version.jl index 08938b3f48af9..e7268f9a9fe21 100644 --- a/base/version.jl +++ b/base/version.jl @@ -244,7 +244,7 @@ function banner(io::IO = STDOUT) commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))" end end - commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))": "" + commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))" : "" if have_color c = text_colors diff --git a/doc/src/manual/control-flow.md b/doc/src/manual/control-flow.md index e06586239edd1..f44be2f49ac18 100644 --- a/doc/src/manual/control-flow.md +++ b/doc/src/manual/control-flow.md @@ -187,7 +187,9 @@ a ? b : c The expression `a`, before the `?`, is a condition expression, and the ternary operation evaluates the expression `b`, before the `:`, if the condition `a` is `true` or the expression `c`, after -the `:`, if it is `false`. +the `:`, if it is `false`. Note that the spaces around `?` and `:` are mandatory: an expression +like `a?b:c` is not a valid ternary expression (but a newline is acceptable after both the `?` and +the `:`). The easiest way to understand this behavior is to see an example. In the previous example, the `println` call is shared by all three branches: the only real choice is which literal string to diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 49c5e6cfd40c1..28496f5d239cd 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -736,11 +736,20 @@ (cond ((eq? (peek-token s) '?) (begin (if (not (ts:space? s)) (syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?"))) - (take-token s) + (take-token s) ; take the ? + (let ((t (with-whitespace-newline (without-range-colon (peek-token s))))) + (if (not (ts:space? s)) + (syntax-deprecation s (string (deparse ex) " ?" (deparse t)) (string (deparse ex) " ? " (deparse t))))) (let ((then (without-range-colon (parse-eq* s)))) - (if (not (eq? (take-token s) ':)) - (error "colon expected in \"?\" expression") - (list 'if ex then (parse-eq* s)))))) + (if (not (eq? (peek-token s) ':)) + (error "colon expected in \"?\" expression")) + (if (not (ts:space? s)) + (syntax-deprecation s (string (deparse ex) " ? " (deparse then) ":") (string (deparse ex) " ? " (deparse then) " :"))) + (take-token s) ; take the : + (let ((t (with-whitespace-newline (peek-token s)))) + (if (not (ts:space? s)) + (syntax-deprecation s (string (deparse ex) " ? " (deparse then) " :" t) (string (deparse ex) " ? " (deparse then) " : " t)))) + (list 'if ex then (parse-eq* s))))) (else ex)))) (define (parse-arrow s) (parse-RtoL s parse-or is-prec-arrow? (eq? t '-->) parse-arrow)) @@ -1996,8 +2005,10 @@ (read (open-input-string (string #\" s #\")))))) (define-macro (check-identifier ex) - `(if (or (syntactic-op? ,ex) (eq? ,ex '....)) - (error (string "invalid identifier name \"" ,ex "\"")))) + `(begin (if (or (syntactic-op? ,ex) (eq? ,ex '....)) + (error (string "invalid identifier name \"" ,ex "\""))) + (if (eq? ,ex '?) + (syntax-deprecation s "`?` used as an identifier" "")))) ; merge with above check in v1.0 ;; parse numbers, identifiers, parenthesized expressions, lists, vectors, etc. (define (parse-atom s (checked #t)) diff --git a/test/enums.jl b/test/enums.jl index 243650b27c643..ea4169af7b8aa 100644 --- a/test/enums.jl +++ b/test/enums.jl @@ -78,7 +78,7 @@ end @test Integer(_zerobi) == 1 # can't use non-identifiers as enum members -@test_throws ArgumentError eval(:(@enum(Test2, ?))) +@test_throws ArgumentError eval(:(@enum Test2 x ? 1 : 2)) @test_throws ArgumentError eval(:(@enum Test22 1=2)) # other Integer types of enum members