Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong undefined function warning #14058

Open
dominicletz opened this issue Dec 11, 2024 · 3 comments
Open

Wrong undefined function warning #14058

dominicletz opened this issue Dec 11, 2024 · 3 comments

Comments

@dominicletz
Copy link
Contributor

Elixir and Erlang/OTP versions

elixir 1.18.0-rc.0
erlang 26.2.5.3

Operating system

Linux

Current behavior

Compiling:

defmodule TypeBug do
  def file_monitor_backened?() do
    case :os.type() do
      {:unix, :darwin} -> :fsevents
      {:unix, :linux} -> :inotifywait
      {:win32, :nt} -> :inotifywait_win32
      _ -> nil
    end
    |> case do
      nil -> false
      backend -> backend.find_executable() != false
    end
  end
end

produces this warning:

   warning: nil.find_executable/0 is undefined (module nil is not available or is yet to be defined)
    │
 14 │         backend.find_executable() != false~
    │
    └─ lib/type_bug.ex:11:26: TypeBug.has_file_monitor_backened?/0

Expected behavior

There should be no warning, since the nil case is handled already.

@josevalim
Copy link
Member

josevalim commented Dec 11, 2024

This is similar to #14043. You should tag the results instead, it will be addressed on v1.19:

defmodule TypeBug do
  def file_monitor_backened?() do
    case :os.type() do
      {:unix, :darwin} -> {:ok, :fsevents}
      {:unix, :linux} -> {:ok, :inotifywait}
      {:win32, :nt} -> {:ok, :inotifywait_win32}
      _ -> :error
    end
    |> case do
      :error -> false
      {:ok, backend} -> backend.find_executable() != false
    end
  end
end

@josevalim josevalim changed the title Wrong type deduction warning Wrong undefined function warning Dec 11, 2024
@harrisi

This comment has been minimized.

@josevalim
Copy link
Member

Thank you, addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants