Skip to content

Commit 5901ca5

Browse files
committed
un-deprecate (;) and make it parse to an empty named tuple
fixes #30115
1 parent 7426625 commit 5901ca5

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Language changes
3232
(in addition to the one that enters the help mode) to see the full
3333
docstring. ([#25930])
3434

35+
* The syntax `(;)` (which was deprecated in v1.4) now creates an empty named tuple ([#30115]).
36+
3537
Multi-threading changes
3638
-----------------------
3739

base/show.jl

+7-10
Original file line numberDiff line numberDiff line change
@@ -1258,16 +1258,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
12581258
elseif head === :tuple
12591259
print(io, "(")
12601260
if nargs > 0 && is_expr(args[1], :parameters)
1261-
if nargs == 1 && isempty(args[1].args)
1262-
# TODO: for now avoid printing (;)
1263-
show_unquoted_expr_fallback(io, args[1], indent, quote_level)
1264-
print(io, ',')
1265-
else
1266-
show_list(io, args[2:end], ", ", indent, 0, quote_level)
1267-
nargs == 2 && print(io, ',')
1268-
print(io, "; ")
1269-
show_list(io, args[1].args, ", ", indent, 0, quote_level, false, true)
1261+
show_list(io, args[2:end], ", ", indent, 0, quote_level)
1262+
nargs == 2 && print(io, ',')
1263+
print(io, ";")
1264+
if !isempty(args[1].args)
1265+
print(io, " ")
12701266
end
1267+
show_list(io, args[1].args, ", ", indent, 0, quote_level, false, true)
12711268
else
12721269
show_list(io, args, ", ", indent, 0, quote_level)
12731270
nargs == 1 && print(io, ',')
@@ -1314,7 +1311,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
13141311
func_args = args[2:end]
13151312

13161313
# :kw exprs are only parsed inside parenthesized calls
1317-
if any(a->is_expr(a, :kw), func_args)
1314+
if any(a->is_expr(a, :kw), func_args) || (!isempty(func_args) && is_expr(func_args[1], :parameters))
13181315
show_call(io, head, func, func_args, indent, quote_level, true)
13191316

13201317
# scalar multiplication (i.e. "100x")

src/julia-parser.scm

+1-3
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,7 @@
19211921
(and (null? first) (null? blk)
19221922
;; all semicolons inside ()
19231923
(if (length= (car args) 1)
1924-
(begin (parser-depwarn s "(;)" "begin end")
1925-
;; should eventually be (tuple (parameters))
1926-
`(block))
1924+
`(tuple (parameters))
19271925
`(block)))))))
19281926
(and (null? first) (null? args) (not comma?)
19291927
(error "unreachable"))

test/show.jl

+3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ end
220220
@test repr(:((a=1,;x=2))) == ":((a = 1,; x = 2))"
221221
@test repr(:((a=1,3;x=2))) == ":((a = 1, 3; x = 2))"
222222
@test repr(:(g(a,; b))) == ":(g(a; b))"
223+
@test repr(:(;)) == ":((;))"
224+
@test repr(:(-(;x))) == ":(-(; x))"
225+
@test repr(:(+(1, 2;x))) == ":(+(1, 2; x))"
223226
for ex in [Expr(:call, :f, Expr(:(=), :x, 1)),
224227
Expr(:ref, :f, Expr(:(=), :x, 1)),
225228
Expr(:vect, 1, 2, Expr(:kw, :x, 1)),

test/syntax.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ macro test999_str(args...); args; end
171171

172172
# blocks vs. tuples
173173
@test Meta.parse("()") == Expr(:tuple)
174-
@test_skip Meta.parse("(;)") == Expr(:tuple, Expr(:parameters))
174+
@test Meta.parse("(;)") == Expr(:tuple, Expr(:parameters))
175175
@test Meta.parse("(;;)") == Expr(:block)
176176
@test Meta.parse("(;;;;)") == Expr(:block)
177177
@test_throws ParseError Meta.parse("(,)")
@@ -1323,7 +1323,7 @@ end
13231323
@test Meta.parse("-(x)^2") == Expr(:call, :-, Expr(:call, :^, :x, 2))
13241324
@test Meta.parse("-(a=1)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:(=), :a, 1), 2))
13251325
@test Meta.parse("-(x;y)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x, LineNumberNode(1,:none), :y), 2))
1326-
@test_skip Meta.parse("-(;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:tuple, Expr(:parameters)), 2))
1326+
@test Meta.parse("-(;)^2") == Expr(:call, :^, Expr(:call, :-, Expr(:parameters)), 2)
13271327
@test Meta.parse("-(;;;;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block), 2))
13281328
@test Meta.parse("-(x;;;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x), 2))
13291329
@test Meta.parse("+((1,2))") == Expr(:call, :+, Expr(:tuple, 1, 2))

0 commit comments

Comments
 (0)