Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Julia 0.7 #6

Merged
merged 3 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
# uncomment the following lines to override the default test script
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 0.7.0-alpha
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
6 changes: 3 additions & 3 deletions src/Retry.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Retry

__precompile__(true)

module Retry

export @repeat, @protected, efield, ecode

efield(x, f, default=nothing) = f in fieldnames(x) ? getfield(x, f) : default
efield(x, f, default=nothing) = f in fieldnames(typeof(x)) ? getfield(x, f) : default
ecode(x) = efield(x, :code)

include("repeat_try.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/protected_try.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro protected(try_expr::Expr)
end

# Check for nothing exception at start of catch block...
unshift!(catch_block.args, :($exception == nothing && rethrow($exception)))
pushfirst!(catch_block.args, :($exception == nothing && rethrow($exception)))

# Check rethrow flag at end of catch block...
push!(catch_block.args, :($exception == nothing || rethrow($exception)))
Expand Down
58 changes: 22 additions & 36 deletions src/repeat_try.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,56 +77,42 @@

# Check that "expr" is "try ... catch err ... [finalise ...] end"

function check_try_catch(expr, require_exception_variable::Bool)

@assert expr.head == :try "" *
"""Expected "try/catch" expression as argument."""

@assert expr.args[3].head == :block

function check_try_catch(expr::Expr, require_exception_variable::Bool)
if expr.head !== :try
throw(ArgumentError("Expected a `try`/`catch` expression argument"))
end
if require_exception_variable
@assert typeof(expr.args[2]) == Symbol "" *
"""Expected exception vairable name."""
expr.args[2] isa Symbol || throw(ArgumentError("Expected exception variable name"))
else
if typeof(expr.args[2]) != Symbol
if !isa(expr.args[2], Symbol)
@assert expr.args[2] == false
expr.args[2] = :err
end
end


return (try_block, exception, catch_block) = expr.args
return (expr.args...,)
end


# Check that "expr" is "@macrocall if ... end".

function check_macro_if(expr)

@assert expr.head == :macrocall &&
((length(expr.args) == 2 && # Julia <= 0.6
typeof(expr.args[2]) == Expr &&
expr.args[2].head == :if) ||
(length(expr.args) == 3 && # Julia >= 0.7
typeof(expr.args[2]) == Expr &&
typeof(expr.args[3]) == Expr &&
expr.args[2].head == :line &&
expr.args[3].head == :if)) "" *
"""$(expr.args[1]) expects "if" expression as argument."""

if_expr = expr.args[end]

@assert length(if_expr.args) == 2 &&
if_expr.args[2].head == :block "" *
""""else" not allowed in $(expr.args[1]) expression."""

return if_expr
function check_macro_if(expr::Expr)
if !(expr.head == :macrocall && length(expr.args) == 3)
throw(ArgumentError("Expected macro call with a single expression argument"))
end
(macroname::Symbol, lineinfo::LineNumberNode, ifexpr::Expr) = expr.args
if ifexpr.head !== :if
throw(ArgumentError("$macroname: expecting an `if` expression"))
end
if !(length(ifexpr.args) == 2 && ifexpr.args[2].head == :block)
throw(ArgumentError("$macroname: `else` expression is not allowed"))
end
return ifexpr
end


function esc_args!(expr::Expr)
for (i, arg) in enumerate(expr.args)
if isa(arg, Symbol) || arg.head != :line
if isa(arg, Symbol) || !isa(arg, LineNumberNode)
expr.args[i] = esc(arg)
end
end
Expand Down Expand Up @@ -185,14 +171,14 @@ macro repeat(max, try_expr::Expr)

# Replace @ignore/@retry macro call with modified if expression...
catch_block.args[i] = if_expr
elseif expr.head != :line
elseif !isa(expr, LineNumberNode)
catch_block.args[i] = esc(expr)
end
end

# Check for nothing exception at start of catch block...
insert!(catch_block.args, 2, :($exception == nothing && rethrow()))
unshift!(catch_block.args, :(ignore = false))
pushfirst!(catch_block.args, :(ignore = false))

# Rethrow at end of catch block...
push!(catch_block.args, :(ignore || rethrow($exception)))
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


using Retry
using Base.Test
using Test


mutable struct TestException <: Exception
Expand Down