PragTob

PragTob

Way to selectively ignore elixir warnings (use case: tests in a library)

:waving_hand:

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 :slight_smile:

Most Liked

josevalim

josevalim

Creator of Elixir

The workaround for now is to write: Process.get(:unused, value). We will have a leaner way in the future.

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement