Elixir: :erlang.map_get unnecessary compile warning in guard

Created on 28 Apr 2020  路  4Comments  路  Source: elixir-lang/elixir

Erlang/OTP 23 [RELEASE CANDIDATE 3] [erts-10.7.1] [source-9a6e292336] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.11.0-dev) - press Ctrl+C to exit (type h() ENTER for help)

This warning happens when using two :erlang.map_get.

Only happens when using mix compile, pasting this code into shell will not trigger a warning.

defmodule Test do
  def test(map) when :erlang.map_get(map,:a) < :erlang.map_get(map,:b) do
    map
  end
  def test(map) do
    map
  end
end
warning: incompatible types:

    :a !~ %{}

in expression:

    :erlang.map_get(map, :a)

Conflict found at
  lib/test.ex:2: Test.test/1

Most helpful comment

The warning is correct, you have the arguments flipped. It should be :erlang.map_get(:a, map).

All 4 comments

The warning is correct, you have the arguments flipped. It should be :erlang.map_get(:a, map).

Ah right, lol. Would it be then be an issue the warning is not triggered if copy+pasting the code into REPL?

No, all warnings are not emitted in the REPL. Some checks are only be performed when code is compiled with the parallel compiler which is not the case for the shell.

Thanks I am closing this sorry for my silly mistake.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josevalim picture josevalim  路  3Comments

Paddy3118 picture Paddy3118  路  3Comments

eproxus picture eproxus  路  3Comments

chulkilee picture chulkilee  路  3Comments

LucianaMarques picture LucianaMarques  路  3Comments