Skip to content

Commit

Permalink
Merge #925
Browse files Browse the repository at this point in the history
925: add test for literal getproperty overwrite r=oxinabox a=mzgubic

Another small thing that came from #922 , namely #922 (comment).

Writing a separate @adjoint for `literal_getproperty`, which shouldn't be done, passes all tests at the moment. This test will fail if a custom adjoint is written for `literal_getproperty`.

@simeonschaub this is from our discussion yesterday

Co-authored-by: Miha Zgubic <[email protected]>
  • Loading branch information
bors[bot] and Miha Zgubic authored Mar 25, 2021
2 parents 2717d48 + 12d59d0 commit 851a649
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 851a649

Please sign in to comment.