Skip to content

Commit ecab331

Browse files
committed
Merge branch 'cb/ternary_spaces'
2 parents e5ca368 + 13e1924 commit ecab331

File tree

11 files changed

+36
-19
lines changed

11 files changed

+36
-19
lines changed

NEWS.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ Deprecated or removed
156156
and the Base signal processing functions which used FFTs are now in DSP.jl ([#21956]).
157157

158158
* The `corrected` positional argument to `cov` has been deprecated in favor of
159-
a keyword argument with the same name (#21709).
159+
a keyword argument with the same name ([#21709]).
160160

161-
* Omitting a space between the condition and `?` in a ternary expression has been deprecated.
161+
* Omitting spaces around the `?` and the `:` tokens in a ternary expression has been deprecated.
162162
Ternaries must now include some amount of whitespace, e.g. `x ? a : b` rather than
163-
`x? a : b` ([#22523]).
163+
`x?a:b` ([#22523] and [#22712]).
164+
165+
* `?` can no longer be used as an identifier name ([#22712])
164166

165167
* The method `replace(s::AbstractString, pat, r, count)` with `count <= 0` is deprecated
166168
in favor of `replace(s::AbstractString, pat, r, typemax(Int))` ([#22325]).
@@ -1000,4 +1002,6 @@ Command-line option changes
10001002
[#22310]: https://github.com/JuliaLang/julia/issues/22310
10011003
[#22523]: https://github.com/JuliaLang/julia/issues/22523
10021004
[#22532]: https://github.com/JuliaLang/julia/issues/22532
1005+
[#22709]: https://github.com/JuliaLang/julia/issues/22709
1006+
[#22712]: https://github.com/JuliaLang/julia/issues/22712
10031007
[#22732]: https://github.com/JuliaLang/julia/issues/22732

base/docs/helpdb/Base.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ the byte representation is different.
250250
251251
This would create a 25-by-30000 `BitArray`, linked to the file associated with stream `s`.
252252
"""
253-
Mmap.mmap(io, ::BitArray, dims = ?, offset = ?)
253+
Mmap.mmap(io, ::BitArray, dims, offset)
254254

255255
"""
256256
sizeof(T)
@@ -2151,7 +2151,7 @@ julia> pop!(d, "e", 4)
21512151
4
21522152
```
21532153
"""
2154-
pop!(collection,key,?)
2154+
pop!(collection,key,default)
21552155

21562156
"""
21572157
pop!(collection) -> item

base/grisu/bignum.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function generateshortestdigits!(num,den,minus,plus,is_even,buffer)
7979
in_delta_room_minus = is_even ?
8080
Bignums.lessequal(num,minus) : Bignums.less(num,minus)
8181
in_delta_room_plus = is_even ?
82-
Bignums.pluscompare(num,plus,den) >= 0: Bignums.pluscompare(num,plus,den) > 0
82+
Bignums.pluscompare(num,plus,den) >= 0 : Bignums.pluscompare(num,plus,den) > 0
8383
if !in_delta_room_minus && !in_delta_room_plus
8484
Bignums.times10!(num)
8585
Bignums.times10!(minus)

base/libgit2/repository.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function reset!(repo::GitRepo, obj::Nullable{<:GitObject}, pathspecs::AbstractSt
351351
@check ccall((:git_reset_default, :libgit2), Cint,
352352
(Ptr{Void}, Ptr{Void}, Ptr{StrArrayStruct}),
353353
repo.ptr,
354-
isnull(obj) ? C_NULL: Base.get(obj).ptr,
354+
isnull(obj) ? C_NULL : Base.get(obj).ptr,
355355
collect(pathspecs))
356356
return head_oid(repo)
357357
end

base/linalg/matmul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ end
372372
# blas.jl defines matmul for floats; other integer and mixed precision
373373
# cases are handled here
374374

375-
lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1:2), size(M, t=='N' ? 2:1))
375+
lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1 : 2), size(M, t=='N' ? 2 : 1))
376376

377377
function copy!(B::AbstractVecOrMat, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat, ir_src::UnitRange{Int}, jr_src::UnitRange{Int})
378378
if tM == 'N'

base/linalg/special.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626

2727
convert(::Type{Tridiagonal}, A::Bidiagonal{T}) where {T} =
2828
Tridiagonal(A.uplo == 'U' ? zeros(T, size(A.dv,1)-1) : A.ev, A.dv,
29-
A.uplo == 'U' ? A.ev:zeros(T, size(A.dv,1)-1))
29+
A.uplo == 'U' ? A.ev : zeros(T, size(A.dv,1)-1))
3030

3131
function convert(::Type{Bidiagonal}, A::SymTridiagonal)
3232
if !iszero(A.ev)

base/parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function parse(str::AbstractString, pos::Int; greedy::Bool=true, raise::Bool=tru
223223
bstr = String(str)
224224
ex, pos = ccall(:jl_parse_string, Any,
225225
(Ptr{UInt8}, Csize_t, Int32, Int32),
226-
bstr, sizeof(bstr), pos-1, greedy ? 1:0)
226+
bstr, sizeof(bstr), pos-1, greedy ? 1 : 0)
227227
if raise && isa(ex,Expr) && ex.head === :error
228228
throw(ParseError(ex.args[1]))
229229
end

base/version.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function banner(io::IO = STDOUT)
244244
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
245245
end
246246
end
247-
commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))": ""
247+
commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))" : ""
248248

249249
if have_color
250250
c = text_colors

doc/src/manual/control-flow.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ a ? b : c
187187

188188
The expression `a`, before the `?`, is a condition expression, and the ternary operation evaluates
189189
the expression `b`, before the `:`, if the condition `a` is `true` or the expression `c`, after
190-
the `:`, if it is `false`.
190+
the `:`, if it is `false`. Note that the spaces around `?` and `:` are mandatory: an expression
191+
like `a?b:c` is not a valid ternary expression (but a newline is acceptable after both the `?` and
192+
the `:`).
191193

192194
The easiest way to understand this behavior is to see an example. In the previous example, the
193195
`println` call is shared by all three branches: the only real choice is which literal string to

src/julia-parser.scm

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,20 @@
736736
(cond ((eq? (peek-token s) '?)
737737
(begin (if (not (ts:space? s))
738738
(syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?")))
739-
(take-token s)
739+
(take-token s) ; take the ?
740+
(let ((t (with-whitespace-newline (without-range-colon (peek-token s)))))
741+
(if (not (ts:space? s))
742+
(syntax-deprecation s (string (deparse ex) " ?" (deparse t)) (string (deparse ex) " ? " (deparse t)))))
740743
(let ((then (without-range-colon (parse-eq* s))))
741-
(if (not (eq? (take-token s) ':))
742-
(error "colon expected in \"?\" expression")
743-
(list 'if ex then (parse-eq* s))))))
744+
(if (not (eq? (peek-token s) ':))
745+
(error "colon expected in \"?\" expression"))
746+
(if (not (ts:space? s))
747+
(syntax-deprecation s (string (deparse ex) " ? " (deparse then) ":") (string (deparse ex) " ? " (deparse then) " :")))
748+
(take-token s) ; take the :
749+
(let ((t (with-whitespace-newline (peek-token s))))
750+
(if (not (ts:space? s))
751+
(syntax-deprecation s (string (deparse ex) " ? " (deparse then) " :" t) (string (deparse ex) " ? " (deparse then) " : " t))))
752+
(list 'if ex then (parse-eq* s)))))
744753
(else ex))))
745754

746755
(define (parse-arrow s) (parse-RtoL s parse-or is-prec-arrow? (eq? t '-->) parse-arrow))
@@ -1996,8 +2005,10 @@
19962005
(read (open-input-string (string #\" s #\"))))))
19972006

19982007
(define-macro (check-identifier ex)
1999-
`(if (or (syntactic-op? ,ex) (eq? ,ex '....))
2000-
(error (string "invalid identifier name \"" ,ex "\""))))
2008+
`(begin (if (or (syntactic-op? ,ex) (eq? ,ex '....))
2009+
(error (string "invalid identifier name \"" ,ex "\"")))
2010+
(if (eq? ,ex '?)
2011+
(syntax-deprecation s "`?` used as an identifier" "")))) ; merge with above check in v1.0
20012012

20022013
;; parse numbers, identifiers, parenthesized expressions, lists, vectors, etc.
20032014
(define (parse-atom s (checked #t))

test/enums.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878
@test Integer(_zerobi) == 1
7979

8080
# can't use non-identifiers as enum members
81-
@test_throws ArgumentError eval(:(@enum(Test2, ?)))
81+
@test_throws ArgumentError eval(:(@enum Test2 x ? 1 : 2))
8282
@test_throws ArgumentError eval(:(@enum Test22 1=2))
8383

8484
# other Integer types of enum members

0 commit comments

Comments
 (0)