Existing issue
Elixir and Erlang/OTP versions
Erlang/OTP 28 [erts-16.4.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Elixir 1.20.1 (compiled with Erlang/OTP 28)
Operating system
any
Current behavior
The following code emits a warning:
defmodule TRedundant do
def f(x, <<x::binary>>), do: 1
def f(a, b) when is_binary(a) and is_binary(b), do: 2
end
warning: the following clause is redundant:
def f(a, b) when is_binary(a) and is_binary(b)
it has type:
binary(), binary()
previous clauses have already matched on the following types:
binary(), binary()
└─ iex:3: TRedundant.f/2
Both clauses are reachable:
iex(2)> TRedundant.f("a", "a")
1
iex(3)> TRedundant.f("a", "b")
2
Expected behavior
No warning or a documented false positive. Can the type system encode that arguments are the same subtype of binary?
This code does not warn
defmodule TRedundant do
def f(x, x) when is_binary(x), do: 1
def f(a, b) when is_binary(a) and is_binary(b), do: 2
end
Existing issue
Elixir and Erlang/OTP versions
Erlang/OTP 28 [erts-16.4.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Elixir 1.20.1 (compiled with Erlang/OTP 28)
Operating system
any
Current behavior
The following code emits a warning:
Both clauses are reachable:
Expected behavior
No warning or a documented false positive. Can the type system encode that arguments are the same subtype of binary?
This code does not warn