title: Dialyzer says function will never be called, even though it is
body: <p>I am using the elixir_talk library. After connecting I want to call a private function once connected to beanstalkd. I just added typespecs and ran Dialyzer (via dialyxir). I get the errors:</p>
  
  <pre><code>my_module.ex:3: The specification for 'Elixir.MyModule':f/0 states that the function might also return 'ok' | {'error',_} but the inferred return is none()
  my_module.ex:4: Function f/0 has no local return
  my_module.ex:14: Function g/1 will never be called
  </code></pre>
  
  <p>The minimal example I could find that produces this is</p>
  
  <pre><code>defmodule MyModule do
    @spec f() :: :ok | {:error, term}
    def f() do
      case ElixirTalk.connect('127.0.0.1', 11300) do
        {:ok, conn} -&gt;
          g(conn)
        {:error, err} -&gt;
          {:error, err}
      end
    end
  
    @spec g(pid) :: :ok
    defp g(pid) do
      :ok
    end
  end
  </code></pre>
  
  <p>If I replace the call to <code>ElixirTalk.connect</code> with a call to <code>spawn</code> instead, Dialyzer no longer reports any problems.</p>
  
  <pre><code>defmodule MyModule do
    @spec f() :: :ok
    def f() do
      x = spawn fn -&gt; :done end
      g(x)
    end
  
    @spec g(pid) :: :ok
    defp g(pid) do
      :ok
    end
  end
  </code></pre>
  
  <p>Does anyone know why Dialyzer is getting confused here?</p>