How to nest `@auto_hash_equals` & `@with_kw`?

How to nest the 2 macros? If I have both AutoHashEquals.@auto_hash_equals & Parameters.@with_kw applied onto a type definition. Either @auto_hash_equals @with_kw or @with_kw @auto_hash_equals is not working:

julia> @auto_hash_equals(@with_kw struct AAA
           a::String
           b
           c = [1, 1, 1]
       end)
ERROR: LoadError: AssertionError: typ.head == :type || typ.head == :struct
Stacktrace:
 [1] @auto_hash_equals(::LineNumberNode, ::Module, ::Any) at /Users/xxx/.julia/packages/AutoHashEquals/tDuUH/src/AutoHashEquals.jl:67
in expression starting at REPL[3]:1
julia> @with_kw(@auto_hash_equals struct AAA
           a::String
           b
           c = [1, 1, 1]
       end)
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.

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] with_kw(::Expr, ::Module, ::Bool) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:307
 [3] @with_kw(::LineNumberNode, ::Module, ::Any) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:631
in expression starting at REPL[4]:100 

This isn’t ideal, but because the transformations these macros do are somewhat orthogonal, you can just write the struct twice:

using Parameters, AutoHashEquals

@with_kw struct AAA
    a::String
    b
    c = [1, 1, 1]
end

@auto_hash_equals struct AAA
    a::String
    b
    c
end

julia> AAA(a = "hi", b = 1) == AAA("hi", 1, [1, 1, 1])
true
2 Likes

Found a package that solves this problem: https://github.com/jw3126/StructHelpers.jl

struct S
    a
    b
end

@batteries S
@batteries S hash=false # don't overload `Base.hash`
@batteries S kwconstructor=true # add a keyword constructor