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
This is because your code is within a quote block. You can mark it as generated:
quote generated: true do
end
bugnano
Thank you very much, it worked ![]()
Popular in Troubleshooting
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









