You'd have to try this out, but it might work to add the additional enforced keys in __before_compile__ instead.
Allen Madsen http://www.allenmadsen.com On Thu, Mar 7, 2019 at 8:20 AM José Valim <[email protected]> wrote: > This is tricky because I can see someone using @enforce_keys to define a > default value and they may want to override it later on. > > I think there is no right answer but given there is a cost of change, I > would suggest to keep the behaviour as is. > > > *José Valim* > www.plataformatec.com.br > Skype: jv.ptec > Founder and Director of R&D > > > On Thu, Mar 7, 2019 at 1:52 PM Krzysztof Wende <[email protected]> > wrote: > >> In case we want to define a macro that requires some keys from the >> struct, @enforce_keys should have `accumulate: true` >> Otherwise we cannot require some fields from a structures in multiple >> places. >> >> We could use >> ``` >> quote do >> @enforce_keys [:key] ++ (Module.get_attribute(__MODULE__, >> :enforce_keys) || []) >> end >> ``` >> in __using__ >> But this way if we do `use` before our own @enforce_keys the key will get >> overwritten. >> If we allowed that to accumulate we could do @enforce_keys many time >> still respecting all of them >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/213ebf4b-c4b3-4468-b191-efe9c203f403%40googlegroups.com >> <https://groups.google.com/d/msgid/elixir-lang-core/213ebf4b-c4b3-4468-b191-efe9c203f403%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BbbA%2BRWdQKKmS_Av94tz9xxXROSAWxYXThU7RpK4p5Bw%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BbbA%2BRWdQKKmS_Av94tz9xxXROSAWxYXThU7RpK4p5Bw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cs0tucbbgHfznFpuvcA8Ws67V0HEAwKOV_nQ_K7tdPNhg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
