Are there some differences between 1.10.4 and 1.11.1 in case of passing structures into |> operator

Sample Code

defmodule Data do
 defstruct name: "Alex"
end

defmodule Test do
  def run(name) do
    changeset = %Data{name: name}
    |> case do
      change when change.name == "" ->
        IO.puts "NIL"
      _ ->
        IO.puts "WHAT??"
    end
    IO.puts changeset
  end
end
  • run code above, i met errors only when compiling with 1.10.4
  • looks working in case of 1.11.1

Error message

Erlang/OTP 23 [erts-11.1.2] [source] [64-bit] [smp:40:40] [ds:40:40:10] [async-threads:1] [hipe]
** (CompileError) test.exs:11: cannot invoke remote function change.name/0 inside guards
    (stdlib 3.13.2) lists.erl:1358: :lists.mapfoldl/3
    (elixir 1.10.4) expanding macro: Kernel.|>/2
  • assume that there are some differences to pass structures into |> operator between 1.10.4 and 1.11.1
  • any idea or need to know where i can look up in elixir source code to find out associated with this.

Thanks.

The difference is about the change when change.name == "" part. Accessing map fields using that syntax in guards wasn’t supported before 1.11.

Elixir v1.11 adds the is_struct/2, is_exception/1, and is_exception/2 guards. It also adds support for the map.field syntax in guards.

from https://elixir-lang.org/blog/2020/10/06/elixir-v1-11-0-released/

3 Likes

That is not related to how structs are piped, thats simply because “dot access” has been enabled for guards with Elixir 1.11:

https://github.com/elixir-lang/elixir/blob/v1.11/CHANGELOG.md#v1110-2020-10-06

  • [Kernel] Support map.field syntax in guards
2 Likes

Thanks.

i should’ve needed to check out release notes first ^^;

Related topics:

thanks Eiji