ecto_network
ecto_network copied to clipboard
Possible redundant case caught by Elixir 1.18.0
When running the tests/compiling with Elixir 1.18.0, I get the following warnings:
Compiling 1 file (.ex)
warning: this clause in cond will always match:
address_netmask(inet.address)
since it has type:
integer()
where "inet" was given the type:
# type: dynamic(%Postgrex.INET{})
# from: lib/ecto_network/inet.ex:55:29
%Postgrex.INET{} = inet
typing violation found at:
│
59 │ address_netmask(inet.address) -> %{inet | netmask: address_netmask(inet.address)}
│ ~
│
└─ lib/ecto_network/inet.ex:59:39: EctoNetwork.INET.load/1
With the following patch, the warning goes away and all the tests pass:
diff --git a/lib/ecto_network/inet.ex b/lib/ecto_network/inet.ex
index 5f87e2c..ce52a52 100644
--- a/lib/ecto_network/inet.ex
+++ b/lib/ecto_network/inet.ex
@@ -57,7 +57,6 @@ defmodule EctoNetwork.INET do
cond do
address_netmask(inet.address, inet.netmask) -> inet
address_netmask(inet.address) -> %{inet | netmask: address_netmask(inet.address)}
- true -> %{inet | netmask: nil}
end
{:ok, inet}
I am not 100% sure if the tests cover all IP address cases so:
- With this patch will the code still behave correctly?
- Should I go ahead and submit a PR?
Thanks for the report. Let me look and will advise.
Hello,
I believe the patch would be correct. Please feel free to submit a PR if you still wish to do so.