Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba281d3

Browse files
committedNov 9, 2017
fix #24452, deprecate (x...) tuple syntax
1 parent 8d67226 commit ba281d3

14 files changed

+46
-27
lines changed
 

‎base/abstractarraymath.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function repeat(A::AbstractArray;
401401
end
402402

403403
rep_kw2tup(n::Integer) = (n,)
404-
rep_kw2tup(v::AbstractArray{<:Integer}) = (v...)
404+
rep_kw2tup(v::AbstractArray{<:Integer}) = (v...,)
405405
rep_kw2tup(t::Tuple) = t
406406

407407
rep_shapes(A, i, o) = _rshps((), (), size(A), i, o)

‎base/dates/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function DateFormat(f::AbstractString, locale::DateLocale=ENGLISH)
363363
push!(tokens, Delim(length(tran) == 1 ? first(tran) : tran))
364364
end
365365

366-
tokens_tuple = (tokens...)
366+
tokens_tuple = (tokens...,)
367367
return DateFormat{Symbol(f),typeof(tokens_tuple)}(tokens_tuple, locale)
368368
end
369369

‎base/libgit2/gitcredential.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function Base.parse(::Type{GitCredentialHelper}, helper::AbstractString)
173173
cmd_str = "git credential-$helper"
174174
end
175175

176-
GitCredentialHelper(`$(Base.shell_split(cmd_str)...)`)
176+
GitCredentialHelper(`$(Base.shell_split(cmd_str))`)
177177
end
178178

179179
function Base.:(==)(a::GitCredentialHelper, b::GitCredentialHelper)

‎base/linalg/rowvector.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ IndexStyle(::Type{<:RowVector}) = IndexLinear()
124124
# helper function for below
125125
@inline to_vec(rowvec::RowVector) = map(transpose, transpose(rowvec))
126126
@inline to_vec(x::Number) = x
127-
@inline to_vecs(rowvecs...) = (map(to_vec, rowvecs)...)
127+
@inline to_vecs(rowvecs...) = (map(to_vec, rowvecs)...,)
128128

129129
# map: Preserve the RowVector by un-wrapping and re-wrapping, but note that `f`
130130
# expects to operate within the transposed domain, so to_vec transposes the elements

‎base/multidimensional.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ index_ndims() = ()
417417

418418
# combined dimensionality of all indices
419419
# rather than returning N, it returns an NTuple{N,Bool} so the result is inferrable
420-
@inline index_dimsum(i1, I...) = (index_dimsum(I...)...)
420+
@inline index_dimsum(i1, I...) = (index_dimsum(I...)...,)
421421
@inline index_dimsum(::Colon, I...) = (true, index_dimsum(I...)...)
422422
@inline index_dimsum(::AbstractArray{Bool}, I...) = (true, index_dimsum(I...)...)
423423
@inline function index_dimsum(::AbstractArray{<:Any,N}, I...) where N

‎base/subarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ strides(V::SubArray) = substrides(V.parent, V.indexes)
255255

256256
substrides(parent, I::Tuple) = substrides(1, parent, 1, I)
257257
substrides(s, parent, dim, ::Tuple{}) = ()
258-
substrides(s, parent, dim, I::Tuple{ScalarIndex, Vararg{Any}}) = (substrides(s*size(parent, dim), parent, dim+1, tail(I))...)
258+
substrides(s, parent, dim, I::Tuple{ScalarIndex, Vararg{Any}}) = (substrides(s*size(parent, dim), parent, dim+1, tail(I))...,)
259259
substrides(s, parent, dim, I::Tuple{Slice, Vararg{Any}}) = (s, substrides(s*size(parent, dim), parent, dim+1, tail(I))...)
260260
substrides(s, parent, dim, I::Tuple{AbstractRange, Vararg{Any}}) = (s*step(I[1]), substrides(s*size(parent, dim), parent, dim+1, tail(I))...)
261261
substrides(s, parent, dim, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("strides is invalid for SubArrays with indices of type $(typeof(I[1]))"))

‎base/tuple.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endof(t::Tuple) = length(t)
2020
size(t::Tuple, d) = (d == 1) ? length(t) : throw(ArgumentError("invalid tuple dimension $d"))
2121
@eval getindex(t::Tuple, i::Int) = getfield(t, i, $(Expr(:boundscheck)))
2222
@eval getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i), $(Expr(:boundscheck)))
23-
getindex(t::Tuple, r::AbstractArray{<:Any,1}) = ([t[ri] for ri in r]...)
23+
getindex(t::Tuple, r::AbstractArray{<:Any,1}) = ([t[ri] for ri in r]...,)
2424
getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t, find(b)) : throw(BoundsError(t, b))
2525

2626
# returns new tuple; N.B.: becomes no-op if i is out-of-bounds
@@ -137,7 +137,7 @@ end
137137
function _ntuple(f, n)
138138
@_noinline_meta
139139
(n >= 0) || throw(ArgumentError(string("tuple length should be ≥0, got ", n)))
140-
([f(i) for i = 1:n]...)
140+
([f(i) for i = 1:n]...,)
141141
end
142142

143143
# inferrable ntuple (enough for bootstrapping)
@@ -163,7 +163,7 @@ function map(f, t::Any16)
163163
for i=1:n
164164
A[i] = f(t[i])
165165
end
166-
(A...)
166+
(A...,)
167167
end
168168
# 2 argument function
169169
map(f, t::Tuple{}, s::Tuple{}) = ()
@@ -179,7 +179,7 @@ function map(f, t::Any16, s::Any16)
179179
for i = 1:n
180180
A[i] = f(t[i], s[i])
181181
end
182-
(A...)
182+
(A...,)
183183
end
184184
# n argument function
185185
heads(ts::Tuple...) = map(t -> t[1], ts)
@@ -195,7 +195,7 @@ function map(f, t1::Any16, t2::Any16, ts::Any16...)
195195
for i = 1:n
196196
A[i] = f(t1[i], t2[i], map(t -> t[i], ts)...)
197197
end
198-
(A...)
198+
(A...,)
199199
end
200200

201201

‎src/ast.scm

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
(string (car e) (deparse (cadr e)))
5555
(string (deparse (cadr e)) " " (car e) " " (deparse (caddr e)))))
5656
((memq (car e) '($ &))
57-
(string (car e) (deparse (cadr e))))
57+
(if (pair? (cadr e))
58+
(string (car e) "(" (deparse (cadr e)) ")")
59+
(string (car e) (deparse (cadr e)))))
5860
((eq? (car e) '|::|)
5961
(if (length> e 2)
6062
(string (deparse (cadr e)) (car e) (deparse (caddr e)))

‎src/julia-parser.scm

+19-6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@
177177
(define whitespace-newline #f)
178178
; enable parsing `where` with high precedence
179179
(define where-enabled #t)
180+
; allow (x...), parsed as (... x). otherwise a deprecation warning is given (#24452)
181+
(define accept-dots-without-comma #f)
180182

181183
(define current-filename 'none)
182184

@@ -601,7 +603,9 @@
601603
(if *deperror* "ERROR:" "WARNING:") " deprecated syntax \"" what "\""
602604
(if (or (not s) (eq? current-filename 'none))
603605
""
604-
(string " at " current-filename ":" (input-port-line (if (port? s) s (ts:port s)))))
606+
(string " at " current-filename ":" (if (number? s)
607+
s
608+
(input-port-line (if (port? s) s (ts:port s))))))
605609
"."
606610
(if (equal? instead "")
607611
""
@@ -1044,7 +1048,9 @@
10441048
((not un)
10451049
(error (string "\"" op "\" is not a unary operator")))
10461050
(else
1047-
(let* ((arg (parse-unary s))
1051+
(let* ((arg (with-bindings
1052+
((accept-dots-without-comma #t))
1053+
(parse-unary s)))
10481054
(args (if (and (pair? arg) (eq? (car arg) 'tuple))
10491055
(cons op (cdr arg))
10501056
(list op arg))))
@@ -1125,7 +1131,9 @@
11251131
(or (closing-token? next) (newline? next))))
11261132
op)
11271133
((memq op '(& |::|)) (list op (parse-where s parse-call)))
1128-
(else (list op (parse-unary-prefix s)))))
1134+
(else (list op (with-bindings
1135+
((accept-dots-without-comma #t))
1136+
(parse-unary-prefix s))))))
11291137
(parse-atom s))))
11301138

11311139
(define (parse-def s is-func)
@@ -2245,10 +2253,15 @@
22452253
(t (require-token s)))
22462254
(cond ((eqv? t #\) )
22472255
(take-token s)
2256+
;; value in parentheses (x)
22482257
(if (and (pair? ex) (eq? (car ex) '...))
2249-
;; (ex...)
2250-
`(tuple ,ex)
2251-
;; value in parentheses (x)
2258+
(let ((lineno (input-port-line (ts:port s))))
2259+
(if (or accept-dots-without-comma (eq? (peek-token s) '->))
2260+
ex
2261+
(begin (syntax-deprecation lineno
2262+
(string "(" (deparse (cadr ex)) "...)")
2263+
(string "(" (deparse (cadr ex)) "...,)"))
2264+
`(tuple ,ex))))
22522265
ex))
22532266
((eq? t 'for)
22542267
(expect-space-before s 'for)

‎src/macroexpand.scm

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
((atom? x) x)
2121
((and (= d 0) (eq? (car x) '$))
2222
(if (length= x 2)
23-
(if (and (length= (cadr x) 2) (eq? (caadr x) 'tuple)
24-
(vararg? (cadadr x)))
25-
;; splice expr ($ (tuple (... x)))
26-
`(... ,(cadr (cadr (cadr x))))
23+
(if (vararg? (cadr x))
24+
;; splice expr ($ (... x))
25+
`(... ,(cadr (cadr x)))
2726
;; otherwise normal interpolation
2827
(cadr x))
2928
;; in e.g. `quote quote $$(x...) end end` multiple expressions can be

‎test/core.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3184,7 +3184,7 @@ mutable struct D11597{T} <: C11597{T} d::T end
31843184
@test_throws TypeError repr(D11597(1.0))
31853185

31863186
# issue #11772
3187-
@test_throws UndefRefError (Vector{Any}(5)...)
3187+
@test_throws UndefRefError (Vector{Any}(5)...,)
31883188

31893189
# issue #11813
31903190
let a = UInt8[1, 107, 66, 88, 2, 99, 254, 13, 0, 0, 0, 0]
@@ -3204,8 +3204,8 @@ let a = UInt8[0, 0, 0, 0, 0x66, 99, 254, 13, 0, 0, 0, 0]
32043204
f11813(p) = ((Int32(3),UInt8(0x66)),Int32(0)) === unsafe_load(convert(Ptr{Tuple{Tuple{Int32,UInt8},Int32}},p))
32053205
@test f11813(p) === true # redundant comparison test seems to make this test more reliable, don't remove
32063206
end
3207-
let a = (1:1000...),
3208-
b = (1:1000...)
3207+
let a = (1:1000...,),
3208+
b = (1:1000...,)
32093209
@test a == b
32103210
@test a === b
32113211
@test (a == b) === true

‎test/inference.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ const NInt1{N} = Tuple{Int, Vararg{Int, N}}
285285
@test Base.eltype(NInt{1}) === Int
286286
@test Base.eltype(NInt1{0}) === Int
287287
@test Base.eltype(NInt1{1}) === Int
288-
fNInt(x::NInt) = (x...)
288+
fNInt(x::NInt) = (x...,)
289289
gNInt() = fNInt(x)
290290
@test Base.return_types(gNInt, ()) == Any[NInt]
291291
@test Base.return_types(eltype, (NInt,)) == Any[Union{Type{Int}, Type{Union{}}}] # issue 21763

‎test/reflection.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222

2323
function test_code_reflection(freflect, f, types, tester)
2424
tester(freflect, f, types)
25-
tester(freflect, f, (types.parameters...))
25+
tester(freflect, f, (types.parameters...,))
2626
nothing
2727
end
2828

‎test/syntax.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,11 @@ let xs = [:(1+2), :(3+4), :(5+6)]
11311131
@test ex2.args[2:end] == [3,7,11]
11321132
end
11331133

1134+
let x = [3,2,1]
1135+
@test :( $(x...,) ) == (3, 2, 1)
1136+
@test :( $(x...), ) == Expr(:tuple, 3, 2, 1)
1137+
end
1138+
11341139
# issue #23519
11351140
@test Meta.parse("@foo[1]") == Meta.parse("@foo([1])")
11361141
@test Meta.parse("@foo[1 2; 3 4]") == Meta.parse("@foo([1 2; 3 4])")

0 commit comments

Comments
 (0)
Please sign in to comment.