ecto_network icon indicating copy to clipboard operation
ecto_network copied to clipboard

Possible redundant case caught by Elixir 1.18.0

Open hchienjo opened this issue 1 year ago • 2 comments

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:

  1. With this patch will the code still behave correctly?
  2. Should I go ahead and submit a PR?

hchienjo avatar Jan 01 '25 07:01 hchienjo

Thanks for the report. Let me look and will advise.

adam12 avatar Jan 02 '25 20:01 adam12

Hello,

I believe the patch would be correct. Please feel free to submit a PR if you still wish to do so.

adam12 avatar Mar 02 '25 15:03 adam12