Why does dialyzer show no warning here?

Dialyzer gives no warnings for the possible List getting returned, the ''.

defmodule PublicLaw.Tenant do
  @moduledoc """
  Functions for handing the Multi/Single-Tenant scheme.
  """

  @doc """
  Return the subdomain in the HTTP request, or empty string if none.
  Assumes that the hostname is one of two forms:
  * nevada.public.law
  * public.law
  """
  @spec subdomain(Plug.Conn) :: binary()
  def subdomain(conn) do
    case String.split(conn.host, ".") do
      [subd, _domain, _tld] ->
        subd

      _ ->
        ''
    end
  end
end

I had similar question here…

and got nice answers.

TLDR:
As long as one path is ok, there will be no warning.
You can define type like good_response, bad_response.

:: binary() | error_type

2 Likes