How to apply two macros to a struct definition?

I would like to use two macros to add extra functions to one struct, namely
@with_kw (from Parameters.jl )
@auto_hash_equals (from AutoHashEquals.jl ).

using Parameters, AutoHashEqual
@with_kw @auto_hash_equals struct S1
    x::Float64 = 1.0
@auto_hash_equals @with_kw struct S2 
    x::Float64 = 1.0

Is there a way to apply both macros at the same time? Thanks!

I get the following errors.

For S1:

ERROR: LoadError: Only works on type-defs or named tuples.
Make sure to have a space after `@with_kw`, e.g. `@with_kw (a=1,)
Also, make sure to use a trailing comma for single-field NamedTuples.

 [1] error(::String) at ./error.jl:33
 [2] with_kw(::Expr, ::Module, ::Bool) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/Parameters/l76EM/src/Parameters.jl:307
 [3] @with_kw(::LineNumberNode, ::Module, ::Any) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/Parameters/l76EM/src/Parameters.jl:631
in expression starting at REPL[11]:1

For S2:

ERROR: LoadError: AssertionError: typ.head == :type || typ.head == :struct
 [1] @auto_hash_equals(::LineNumberNode, ::Module, ::Any) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/AutoHashEquals/tDuUH/src/AutoHashEquals.jl:67
in expression starting at REPL[9]:1
1 Like

I don’t think there is an easy way. Both macros produce more than just a type-def, but both expect a type-def as an input. The only way to do this would be to make them somehow compatible.

Thanks for the reply! Guess it is just not possible.