PragTob
Way to selectively ignore elixir warnings (use case: tests in a library)
![]()
This is a bit of an odd scenario I realize and calling me over cautious is fair.
I want to know if there is, or is envisioned to be, a way to selectively ignore type warnings. My current use case is deep_merge
It has a couple of tests that specifically check that the library fails correctly when confronted with the wrong types:
The new elixir type system correctly identifies that these are the wrong types:
warning: incompatible types given to DeepMerge.deep_merge/2:
DeepMerge.deep_merge(%{a: 1}, 2)
given types:
%{a: integer()}, integer()
but expected one of:
(
empty_list() or map() or non_empty_list(term(), term()),
empty_list() or map() or non_empty_list(term(), term())
)
type warning found at:
│
91 │ assert_incompatible(fn -> deep_merge(%{a: 1}, 2) end)
│ ~
│
└─ test/deep_merge_test.exs:91:33: DeepMergeTest."test .deep_merge/2 errors out with incompatible types"/1
My first reaction to that (PR) was to delete these tests.
However, then I actually ran into an incompatibility with the merging behavior inbetween elixir versions. So, I was worried “maybe this would/could break the tests I just removed”.
And so, I re-added the tests.
So, imo the best solution would be to be able to ignore type warnings selectively. But I also realize that my “I want to test that it does what I want when handed the wrong types across elixir versions” is a relative special case.
I suppose I could run those tests only on elixir versions pre 1.20, which is probably what I’m going to do/try to do. That said, another solution to it would still be good imo.
Happy for input and insight on this, thanks ![]()
Most Liked
josevalim
The workaround for now is to write: Process.get(:unused, value). We will have a leaner way in the future.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









