Skip to content

Sigil not working with assert macro in Elixir 1.14 #14

@emaiax

Description

@emaiax

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. :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions