Skip to content

Commit

Permalink
complete try/catch/else test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Jan 29, 2024
1 parent 4d52ed4 commit d56dd27
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ if VERSION >= v"1.8"
# try/catch/else is invalid syntax prior to v1.8
eval(Meta.parse("""
function try_catch_else(cond, x)
x = 2x
try
x = 2x
cond && throw(nothing)
catch
x = 3x
else
x = 2x
end
x
end
"""))
end
Expand All @@ -302,6 +314,13 @@ end
string(err))
end

if VERSION >= v"1.8"
@testset "try/catch/else" begin
@test Zygote.gradient(try_catch_else, false, 1.0) == (nothing, 8.0)
@test_throws "Can't differentiate function execution in catch block" Zygote.gradient(try_catch_else, true, 1.0)
end
end

function foo_try(f)
y = 1
try
Expand Down

0 comments on commit d56dd27

Please sign in to comment.