Skip to content

Commit

Permalink
un-deprecate (;) and make it parse to an empty named tuple
Browse files Browse the repository at this point in the history
fixes #30115
  • Loading branch information
JeffBezanson committed Jan 29, 2020
1 parent 4e2a6e7 commit 7082c5a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Language changes
(in addition to the one that enters the help mode) to see the full
docstring. ([#25930])

* The syntax `(;)` (which was deprecated in v1.4) now creates an empty named tuple ([#30115]).

Multi-threading changes
-----------------------

Expand Down
17 changes: 7 additions & 10 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,16 +1258,13 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
elseif head === :tuple
print(io, "(")
if nargs > 0 && is_expr(args[1], :parameters)
if nargs == 1 && isempty(args[1].args)
# TODO: for now avoid printing (;)
show_unquoted_expr_fallback(io, args[1], indent, quote_level)
print(io, ',')
else
show_list(io, args[2:end], ", ", indent, 0, quote_level)
nargs == 2 && print(io, ',')
print(io, "; ")
show_list(io, args[1].args, ", ", indent, 0, quote_level, false, true)
show_list(io, args[2:end], ", ", indent, 0, quote_level)
nargs == 2 && print(io, ',')
print(io, ";")
if !isempty(args[1].args)
print(io, " ")
end
show_list(io, args[1].args, ", ", indent, 0, quote_level, false, true)
else
show_list(io, args, ", ", indent, 0, quote_level)
nargs == 1 && print(io, ',')
Expand Down Expand Up @@ -1314,7 +1311,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
func_args = args[2:end]

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

# scalar multiplication (i.e. "100x")
Expand Down
4 changes: 1 addition & 3 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,7 @@
(and (null? first) (null? blk)
;; all semicolons inside ()
(if (length= (car args) 1)
(begin (parser-depwarn s "(;)" "begin end")
;; should eventually be (tuple (parameters))
`(block))
`(tuple (parameters))
`(block)))))))
(and (null? first) (null? args) (not comma?)
(error "unreachable"))
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ end
@test repr(:((a=1,;x=2))) == ":((a = 1,; x = 2))"
@test repr(:((a=1,3;x=2))) == ":((a = 1, 3; x = 2))"
@test repr(:(g(a,; b))) == ":(g(a; b))"
@test repr(:(;)) == ":((;))"
@test repr(:(-(;x))) == ":(-(; x))"
@test repr(:(+(1, 2;x))) == ":(+(1, 2; x))"
for ex in [Expr(:call, :f, Expr(:(=), :x, 1)),
Expr(:ref, :f, Expr(:(=), :x, 1)),
Expr(:vect, 1, 2, Expr(:kw, :x, 1)),
Expand Down
4 changes: 2 additions & 2 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ macro test999_str(args...); args; end

# blocks vs. tuples
@test Meta.parse("()") == Expr(:tuple)
@test_skip Meta.parse("(;)") == Expr(:tuple, Expr(:parameters))
@test Meta.parse("(;)") == Expr(:tuple, Expr(:parameters))
@test Meta.parse("(;;;;)") == Expr(:block)
@test_throws ParseError Meta.parse("(,)")
@test_throws ParseError Meta.parse("(;,)")
Expand Down Expand Up @@ -1322,7 +1322,7 @@ end
@test Meta.parse("-(x)^2") == Expr(:call, :-, Expr(:call, :^, :x, 2))
@test Meta.parse("-(a=1)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:(=), :a, 1), 2))
@test Meta.parse("-(x;y)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x, LineNumberNode(1,:none), :y), 2))
@test_skip Meta.parse("-(;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:tuple, Expr(:parameters)), 2))
@test Meta.parse("-(;)^2") == Expr(:call, :^, Expr(:call, :-, Expr(:parameters)), 2)
@test Meta.parse("-(;;;;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block), 2))
@test Meta.parse("-(x;;;)^2") == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x), 2))
@test Meta.parse("+((1,2))") == Expr(:call, :+, Expr(:tuple, 1, 2))
Expand Down

0 comments on commit 7082c5a

Please sign in to comment.