Skip to content

1.20.0-rc.0 - incorrect undefined module warning #15057

@fhunleth

Description

@fhunleth

Elixir and Erlang/OTP versions

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

Elixir 1.20.0-rc.0 (0f9d919) (compiled with Erlang/OTP 28)

Operating system

macOS

Current behavior

Compile the following module:

defmodule Test do
  def default_format(data) do
    case String.Chars.impl_for(data) do
      nil -> inspect(data)
      mod -> mod.to_string(data)
    end
  end
end

The warning that I'm getting is:

    warning: nil.to_string/1 is undefined (module nil is not available or is yet to be defined)
    │
  5 │       mod -> mod.to_string(data)
    │                  ~
    │
    └─ lib/test.ex:5:18: Test.default_format/1

Expected behavior

I was expecting the handling of nil on line 4 to make it so that mod was non-nil on line 5. Adding a guard on line 5 removes the warning as you'd expect.

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