Prevent "method overwritten" warning on julia 0.5#5
Prevent "method overwritten" warning on julia 0.5#5mauro3 merged 1 commit intomauro3:masterfrom timholy:pull-request/c16d389b
Conversation
src/SimpleTraits.jl
Outdated
| # @traitfn f{X,Y; !Tr1{X,Y}}(x::X,y::Y) = ... # which is just sugar for: | ||
| # @traitfn f{X,Y; Not{Tr1{X,Y}}}(x::X,y::Y) = ... | ||
| let dispatch_cache = Set() # to ensure that the trait-dispatch function is defined only once per pair | ||
| global traitfn |
|
Thanks for tackling this! These problematic cases still give warnings (but works otherwise): Ideally one would query the method table to check for the existence of the trait-dispatch function, then add some extra storage to allow over-writing. However, So, I'll merge this and we can revisit this at some point in the future, unless you got a better idea. |
|
I just saw: JuliaLang/julia#17618 Would that fix the overwritten warning? |
|
Yeah, I don't think this can handle renaming the types. Checking the method table isn't ideal either: what if you were intending to redefine the method? That's why I only allow this to prevent redefinition for the opposite member of the pair.
As far as I can tell, no. That seems to be about type redefinition, not method overwriting. I added indentation of the |
|
Yes, the |
On julia 0.5, using trait functions generates a method-overwritten warning. This occurs because the trait-dispatching function
gets generated for both
Tr{X}and!Tr{X}. This PR tries to fix that, by anticipating that traits come in pairs: when the opposite member of the pair arrives, it avoids generating the trait-dispatching function. But kudos to you and your tests: it turns out to be important to do this only once, because if you want to redefine a trait function you need to also redefine the dispatcher (because of julia 265).I thought I had come up with a way where this could still cause trouble:
Counter to my expectation, this still worked properly, so I think (somewhat surprisingly 😄) that this is actually OK.