Will, or should, Elixir 1.20 types warn on this?

Will, or should, Elixir 1.20 types warn when a struct is in a list and a struct’s key is mistyped? Only the uncommented Enum.reject line produces a warning (and already pre-1.20, at least in 1.18). Is there a plan that the shorthand (Enum.reject(& &1.c == 1)) will also warn?

defmodule A do
  defstruct [:b]
end

def test do
  [%A{b: 1}]
  |> Enum.reject(fn %A{} = a -> a.c == 1 end)     # warns
  # |> Enum.reject(fn a -> a.c == 1 end)  # doesn't warn
  # |> Enum.reject(& &1.c == 1)           # doesn't warn
end

Apologies for a potentially ignorant question, as I haven’t been following the compiler development closely.

1 Like

It will eventually warn on shorthand. The code looks simple but getting this particular example to warn via the type system requires parametric types (and a lot of work behind the scenes!).

8 Likes