From d56dd270988e450834b906bf3d1d113db19b12de Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 29 Jan 2024 22:07:45 +0100 Subject: [PATCH] complete try/catch/else test --- test/compiler.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/compiler.jl b/test/compiler.jl index 3fdc7a912..af93ae4f3 100644 --- a/test/compiler.jl +++ b/test/compiler.jl @@ -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 @@ -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