Skip to content

Confusing type warning when checking with true <- x in [] #15411

@novaugust

Description

@novaugust

Existing issue

  • I have searched existing issues and could not find a duplicate.

Elixir and Erlang/OTP versions

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

Elixir 1.20.0-rc.5 (862ff78) (compiled with Erlang/OTP 28)

Operating system

macos

Current behavior

the following code emits a type warning in 1.20 when @attr is an empty list.

defmodule A do 
  @attr Application.compile_env(:my_app, :my_key)

        def foo do
          with true <- :a in @attr, do: :ok
        end
end

presumably due to compiler optimization, the type warning code doesn't look like the written code (simplified repro below)

iex(1)> defmodule C do
        def foo do
        with true <- :a in [], do: :ok
        end
        end
warning: the following pattern will never match:

    true <-
      (
        _ = :a
        false
      )

because the right-hand side has type:

    false

└─ iex:3: C.foo/0

Expected behavior

the pattern referenced should match the code to some degree to help developers know they're fixing the right bit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions