Skip to content

Unexpected BadMapError when calling function via module variable #15219

@slashmili

Description

@slashmili

Elixir and Erlang/OTP versions

I’ve encountered a behavior change in Elixir 1.20.0-rc.3 compared to 1.19.

The following code works as expected in Elixir 1.19, but fails in 1.20.0-rc.3:

defmodule Hello do
  def hi do
    :hello
  end
end

defmodule HelloTest do
  use ExUnit.Case, async: true

  test "calling function" do
    assert Hello.hi() == :hello

    assert mod_names() |> Enum.map(&(&1.hi == :hello))
  end

  def mod_names do
    [Hello]
  end
end

I understand that this code is strange, but that's what I have in one of my projects and the tests are not passing because in this project has many codes like this pattern.

Operating system

linux

Expected behavior

elixir --version
Erlang/OTP 28 [erts-16.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.19.2 (compiled with Erlang/OTP 28)

mix test --trace test/hello_test.exs
Running ExUnit with seed: 132941, max_cases: 1


HelloTest [test/hello_test.exs]
  * test calling function [L#10]warning: using map.field notation (without parentheses) to invoke function Hello.hi() is deprecated, you must add parentheses instead: remote.function()
  test/hello_test.exs:13: anonymous fn/1 in HelloTest."test calling function"/1
  (elixir 1.19.2) lib/enum.ex:1688: Enum."-map/2-lists^map/1-1-"/2
  test/hello_test.exs:13: HelloTest."test calling function"/1
  (ex_unit 1.19.2) lib/ex_unit/runner.ex:528: ExUnit.Runner.exec_test/2
  (stdlib 7.2) timer.erl:599: :timer.tc/2
  (ex_unit 1.19.2) lib/ex_unit/runner.ex:450: anonymous fn/6 in ExUnit.Runner.spawn_test_monitor/4

  * test calling function (8.0ms) [L#10]

Finished in 0.03 seconds (0.03s async, 0.00s sync)
1 test, 0 failures

Current behavior

elixir --version
Erlang/OTP 28 [erts-16.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.20.0-rc.3 (2db87eb) (compiled with Erlang/OTP 28)

mix test --trace test/hello_test.exs
Running ExUnit with seed: 703652, max_cases: 1


HelloTest [test/hello_test.exs]
  * test calling function (2.3ms) [L#10]

  1) test calling function (HelloTest)
     test/hello_test.exs:10
     ** (BadMapError) expected a map, got:

         Hello

     code: assert mod_names() |> Enum.map(&(&1.hi == :hello))
     stacktrace:
       test/hello_test.exs:13: anonymous fn/1 in HelloTest."test calling function"/1
       (elixir 1.20.0-rc.3) lib/enum.ex:1725: Enum."-map/2-lists^map/1-1-"/2
       test/hello_test.exs:13: (test)


Finished in 0.01 seconds (0.01s async, 0.00s sync)
1 test, 1 failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions