meyercm / shorter_maps

Elixir ~M sigil for map shorthand. `~M{id, name} ~> %{id: id, name: name}`
MIT License
231 stars 11 forks source link

Sigil not working with `assert` macro in Elixir 1.14 #14

Open emaiax opened 2 years ago

emaiax commented 2 years ago

Elixir 1.14.0 Erlang/OTP 24

The sigil seems to not be working with ExUnit's assert macro when used as an argument to a function.

To reproduce:

defmodule ShorterMapsTest do
  use ExUnit.Case

  import ShorterMaps

  test "broken" do
    input = %{"name" => "myname", "age" => 123}

    assert %{"input" => ^input} = ~m{input}
    assert %{"input" => input} == ~m{input}

    assert is_input?(input)
    assert is_input?(~m{input})
  end

  defp is_input?(~m{input}), do: true
  defp is_input?(_input), do: false
end

It gives the following error:

== Compilation error in file test/myapp/shorter_maps_test.exs ==
** (ArgumentError) interpolation is not supported with the ~m sigil
    (shorter_maps 2.2.5) expanding macro: ShorterMaps.sigil_m/2
    test/myapp/shorter_maps_test.exs:13: ShorterMapsTest."test broken"/1
    (elixir 1.14.0) expanding macro: Kernel.if/2
    test/myapp/shorter_maps_test.exs:13: ShorterMapsTest."test broken"/1
    (ex_unit 1.14.0) expanding macro: ExUnit.Assertions.assert/1
    test/myapp/shorter_maps_test.exs:13: ShorterMapsTest."test broken"/1

Line 13 is exactly assert is_input?(~m{input}).

This was working fine until Elixir 1.13.x, and now it's broken. I'm not sure where to start digging. :/

emaiax commented 2 years ago

Perhaps it has some relation with #11

meyercm commented 1 year ago

Sorry to have missed when this arrived - this problem seems super annoying - I'll take a look and see what I can find.