Skip to content

Dialyzer warnings around ranges #15037

@michallepicki

Description

@michallepicki

Elixir and Erlang/OTP versions

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

Elixir 1.20.0-dev (88cbabf) (compiled with Erlang/OTP 28)

Operating system

Ubuntu 22.04.5 under WSL 2 on Windows 11

Current behavior

Since f1bbb2c , code with ranges in conditionals where the checked value is already known to be an integer, e.g. like this

defmodule SomeMod do
  def from_unix(integer, unit) do
    total = System.convert_time_unit(integer, unit, :microsecond)
    if total in 1..2 do
      :ok
    else
      :error
    end
  end

  def parse_offset(h1) when is_integer(h1) do
    with true <- h1 in 48..50 do
      :ok
    else
      _ -> :error
    end
  end
end

causes Dialyzer warnings looking like:

lib/some_mod.ex:1: The pattern
          'false' can never match the type
          'true'

lib/some_mod.ex:1: The pattern
          'false' can never match the type
          'true'

additionally these warnings are hard to debug because they point to line 1 (probably because of missing line numbers metadata somewhere in the AST)

Note: I extracted the example from https://github.com/michallepicki/elixir-lang-dialyzer-runs/actions/runs/20669455929/job/59347754340 , in the Elixir codebase there are also similar warnings for the Base module

Expected behavior

No Dialyzer warnings

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