drewr / postal

Clojure email support
MIT License
586 stars 85 forks source link

Resolve reflection warnings #79

Closed sfnelson closed 7 years ago

sfnelson commented 7 years ago

Reflection warnings indicate compile time type ambiguity that is resolved at runtime with a dynamic dispatch. This causes a small runtime cost that is not usually a problem, but can also mask type errors, for example set-body! which claims to accept a javax.mail.Message but actually requires a javax.mail.internet.MimeMessage.

Even if postal does not benefit from resolving type ambiguities, downstream users may have very good reasons for enabling reflection warnings so it would be nice if postal (and similar libraries) could avoid generating reflection warnings in their core namespaces so that they don't generate noise for downstream users.

This change is split into three commits:

1) Enable reflection warnings: this commit is optional, but will help avoid regressions 2) Resolve ambiguities in core namespaces: this commit is the meat of the change 3) Resolve ambiguities in test namespaces: if you accept (1) you probably want this too

I have tried to avoid any changes to behaviour, or the signatures of public vars. The exceptions to this are message->str, where I added a return type hint to resolve a lot of warnings in test code, and add-body!, where I resolved a potential bug where a MimeMessage was expected but the API claims to take a Message. I changed the code to support Message in both paths so that the API remains consistent, but you may prefer to change to MimeMessage and eliminate the extra conditional.

sfnelson commented 7 years ago

This pull request supersedes #54 and resolves #72

drewr commented 7 years ago

OK, 2.0.2 has this merged. Thanks so much @sfnelson!