bugnano

bugnano

What should I do to my library so that Elixir 1.19 and 1.20 do not produce warnings on libraries that implement behaviours?

Hello everyone.

I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub , a library that allows to implement WebTransport servers in Elixir.

Now, the way that library works, is that it exposes some behaviours, and the application author has to implement callbacks. Standard Elixir stuff.

For example, I have defined a callback handle_close as follows:

 @callback handle_close(stream :: Stream.t(), state :: term()) ::
              {:continue, term()} | :close

and the library calls the handle_close callback in this way:

      def handle_info(:wtransport_stream_closed, {%Stream{} = stream, state}) do
        Logger.debug(":wtransport_stream_closed")

        case handle_close(stream, state) do
          {:continue, new_state} ->
            {:noreply, {stream, new_state}}

          _ ->
            {:stop, :normal, {stream, state}}
        end
      end

which means that I pattern match on the return value of the callback.

The problem is that if the application that uses my library only returns {:continue, new_state}, the other branch of the case statement is never executed, and Elixir 1.19+ issues a warning

     warning: the following clause will never match:

         {:continue, new_state} ->

     because it attempts to match on the result of:

         handle_close(stream, state)

     which has type:

         dynamic(:close)

     type warning found at:
     │
 136 │           {:continue, new_state} ->
     │           ~~~~~~~~~~~~~~~~~~~~~~~~~
     │
     └─ wtransport-elixir/lib/wtransport/stream_handler.ex:136: Server.StreamHandler.handle_info/2

As a library author I have no control on what the application does with its callbacks, so what do I have to do on my library in order to make it work without warnings, regardless of the return value of the callback?

Most Liked

woylie

woylie

This is because your code is within a quote block. You can mark it as generated:

quote generated: true do
end
bugnano

bugnano

Thank you very much, it worked :grinning_face:

Where Next?

Popular in Troubleshooting Top

rayex
When I compile hex package io_ansi_plus, I get error “Codepoint failed”. Why? and why are the “Got:” and “Hint:” codepoints identical? It...
New
ChrisAmelia
Currently reading and experimenting through, which is in 1.6 Chapter 7: Sign up | Phoenix Tutorial (Phoenix 1.6) | Softcover.io In regar...
New
bugnano
Hello everyone. I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub ,...
New
rathoud96
Environment Elixir 1.18.3-otp-27 / OTP 27.3.4 Oban 2.20.2 Phoenix 1.7.x db_connection 2.8.1 / Postgrex 0.21.1 Infrastructure: Google Cl...
New
hyperoceanic
Having read the book, I’m keen to explore Ash a bit more, but I’m falling at the first hurdle - the creation of a new project. Here’s my...
New
ktayah
Environment Oban Pro: 1.7.6 Oban: 2.22.1 Issue When a sub-workflow built with Workflow.put_context/2 is attached to a parent via ...
New
tellemiller
We recently started running Oban with Oban Web on PostgreSQL (AWS RDS gp3) and noticed our oban_jobs buffer cache hit ratio sitting at 65...
New
rayex
For hex package islands_score the source @spec for function format/2 is as such: @spec format(t, keyword) :: :ok Why does it show on 4 ...
New
ndan
Oban.Pro.Migration.up(version: "1.7.0", only: :indexes) fails on partitioned oban_jobs table when upgrading Oban Pro from 1.6 to 1.7 def...
New
hakarabakara1
I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I inte...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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

We're in Beta

About us Mission Statement