Skip to content

Commit

Permalink
Merge pull request JuliaLang#23487 from JuliaLang/jb/catchexpr
Browse files Browse the repository at this point in the history
deprecate `catch <expression>`
  • Loading branch information
JeffBezanson committed Aug 30, 2017
2 parents e07eabb + 8522ff0 commit c3f5917
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Language changes
warning, so that this syntax can be disallowed or given a new meaning in a
future version ([#5148]).

* Placing an expression after `catch`, as in `catch f(x)`, is deprecated.
Use `catch; f(x)` instead ([#19987]).

* In `for i = ...`, if a local variable `i` already existed it would be overwritten
during the loop. This behavior is deprecated, and in the future `for` loop variables
will always be new variables local to the loop ([#22314]).
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function mirror_callback(remote::Ptr{Ptr{Void}}, repo_ptr::Ptr{Void},
config = GitConfig(GitRepo(repo_ptr,false))
name_str = unsafe_string(name)
err= try set!(config, "remote.$name_str.mirror", true)
catch -1
catch; -1
finally close(config)
end
err != 0 && return Cint(err)
Expand Down
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,10 @@
(var (if nl #f (parse-eq* s)))
(var? (and (not nl) (or (and (symbol? var) (not (eq? var 'false))
(not (eq? var 'true)))
(and (length= var 2) (eq? (car var) '$)))))
(and (length= var 2) (eq? (car var) '$))
(and (syntax-deprecation s (string "catch " (deparse var) "")
(string "catch; " (deparse var) ""))
#f))))
(catch-block (if (eq? (require-token s) 'finally)
`(block ,(line-number-node s))
(parse-block s))))
Expand Down
10 changes: 5 additions & 5 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ add_method_to_glob_fn!()
@test expand(Main, :(f(d:Int...) = nothing)) == Expr(:error, "\"d:Int\" is not a valid function argument name")

# issue #16517
@test (try error(); catch 0; end) === 0
@test (try error(); catch false; end) === false # false and true are Bool literals, not variables
@test (try error(); catch true; end) === true
f16517() = try error(); catch 0; end
@test (try error(); catch; 0; end) === 0
@test (try error(); catch; false; end) === false # false and true are Bool literals, not variables
@test (try error(); catch; true; end) === true
f16517() = try error(); catch; 0; end
@test f16517() === 0

# issue #16671
Expand All @@ -592,7 +592,7 @@ end

# issue #16686
@test parse("try x
catch test()
catch; test()
y
end") == Expr(:try,
Expr(:block,
Expand Down
2 changes: 1 addition & 1 deletion test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test_code_reflections(test_bin_reflection, code_native)
mktemp() do f, io
OLDSTDOUT = STDOUT
redirect_stdout(io)
@test try @code_native map(abs, rand(3)); true; catch false; end
@test try @code_native map(abs, rand(3)); true; catch; false; end
redirect_stdout(OLDSTDOUT)
nothing
end
Expand Down

0 comments on commit c3f5917

Please sign in to comment.