From 12d59d0271fda986829571fb5f3a7374bb0e6646 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Tue, 23 Mar 2021 17:00:30 +0000 Subject: [PATCH] add test for literal getproperty overwriting --- test/compiler.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/compiler.jl b/test/compiler.jl index 19c010fa4..3cc6dc54d 100644 --- a/test/compiler.jl +++ b/test/compiler.jl @@ -109,3 +109,17 @@ end @test y == 1 @test pb(1) == (nothing, (x = 1, y = nothing), nothing) end + +# this test fails if adjoint for literal_getproperty is added +# https://github.com/FluxML/Zygote.jl/issues/922#issuecomment-804128905 +@testset "overloaded getproperty" begin + struct MyStruct + a + b + end + Base.getproperty(ms::MyStruct, s::Symbol) = s === :c ? ms.a + ms.b : getfield(ms, s) + sumall(ms::MyStruct) = ms.a + ms.b + ms.c + + ms = MyStruct(1, 2) + @test Zygote.gradient(sumall, ms) == ((a = 2, b = 2),) +end