Skip to content

Dialyzer when _ :: true === nil error for ExUnit.Assertions.refute macro #13992

@elvanja

Description

@elvanja

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

Operating system

macOS

Current behavior

While trying to extract some common assertions into a test support module, encountered an issue with dialyzer and refute macro from ExUnit assertions. This is the minimal helper module that exhibits the error:

defmodule Demo.Test.Helpers do
  import ExUnit.Assertions

  def assert_success(log) do
    assert log =~ "success"
    refute log =~ "failure"
  end
end

And this is the result of dialyzer call:

➜ MIX_ENV=test mix dialyzer

Total errors: 1, Skipped: 0, Unnecessary Skips: 27
done in 0m5.49s
test/support/helpers.ex:6:guard_fail
The guard clause:

when _ :: true === nil

can never succeed.

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

Using e.g. refute log =~ "failure", "should refute" solves the problem. Other ideas like assert with not also work. But, it would be nice to know why the default refute fails.

Expected behavior

Expected dialyzer not to complain to refute macro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions