From 8522ff0afb90e0cc98e067d77155c334d570ee1a Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 28 Aug 2017 12:45:03 -0400 Subject: [PATCH] deprecate `catch `. addresses #19987 --- NEWS.md | 3 +++ base/libgit2/callbacks.jl | 2 +- src/julia-parser.scm | 5 ++++- test/parse.jl | 10 +++++----- test/reflection.jl | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0fe173063bc5d..41c50c1bca9fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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]). diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index 4923318738b95..1b288b8edd4f1 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -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) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 32281cca87b27..3a17ab7346eb8 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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)))) diff --git a/test/parse.jl b/test/parse.jl index 2f57e98593752..7d5aaad45964e 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -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 @@ -592,7 +592,7 @@ end # issue #16686 @test parse("try x - catch test() + catch; test() y end") == Expr(:try, Expr(:block, diff --git a/test/reflection.jl b/test/reflection.jl index 11c23ea08f96d..12683a81d95a0 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -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