jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.68k stars 142 forks source link

Error on Dialyxir.Warnings.InvalidContract.format_long #501

Open nikitalocalhost opened 1 year ago

nikitalocalhost commented 1 year ago

Environment

Erlang/OTP 26 [erts-14.0] [source] [64-bit] [smp:16:8] [ds:16:8:10] [async-threads:1] [jit:ns]

Elixir 1.14.4 (compiled with Erlang/OTP 26)
"dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"}

Current behavior

When using --format dialyxir on wrongfully typespeced hello world project dialyxir throws an error:

> mix dialyzer
Finding suitable PLTs
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/home/nlocalhost/Development/Projects/free_ship/_build/dev/dialyxir_erlang-26.0_elixir-1.14.4_deps-dev.plt',
  files: ['/home/nlocalhost/Development/Projects/free_ship/_build/dev/lib/jelly_notes/ebin/Elixir.JellyNotes.beam',
   '/home/nlocalhost/Development/Projects/free_ship/_build/dev/lib/jelly_notes/ebin/Elixir.Web.Application.beam',
   '/home/nlocalhost/Development/Projects/free_ship/_build/dev/lib/jelly_notes/ebin/Elixir.Web.beam'],
  warnings: [:unmatched_returns, :extra_return, :missing_return, :overspecs,
   ...]
]
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m4.42s
Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

Unknown error occurred: %FunctionClauseError{module: Dialyxir.Warnings.InvalidContract, function: :format_long, arity: 1, kind: nil, args: nil, clauses: nil}

Legacy warning:
lib/jelly_notes.ex:15: Invalid type specification for function 'Elixir.JellyNotes':hello/0.
 The success typing is 'Elixir.JellyNotes':hello() -> 'world'
 But the spec is 'Elixir.JellyNotes':hello() -> binary()
 The return types do not overlap
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

Code:

defmodule JellyNotes do
  @moduledoc """
  Documentation for `JellyNotes`.
  """

  @doc """
  Hello world.

  ## Examples

      iex> JellyNotes.hello()
      :world

  """
  @spec hello :: binary()
  def hello do
    :world
  end
end

Dialyzer config:

defmodule JellyNotes.MixProject do
  use Mix.Project

  def project do
    [
      app: :jelly_notes,
      version: "0.1.0",
      elixir: "~> 1.14",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      dialyzer: dialyzer()
    ]
  end

  def application do
    [
      mod: {Web.Application, []},
      extra_applications: [:logger]
    ]
  end

  defp dialyzer do
    [
      flags: [:unmatched_returns, :extra_return, :missing_return, :overspecs]
    ]
  end

  defp deps do
    [
      {:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false},
      {:gradient, github: "esl/gradient", only: [:dev, :test], runtime: false},
      {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
      {:ex_doc, "~> 0.29", only: :dev, runtime: false}
    ]
  end
end

Expected behavior

A long description about an error

atavistock commented 9 months ago

I have the same with Elixir 1.15.5, Erlang 26.1, and Dialyzer 1.4.1

crova commented 9 months ago

We're facing the same on our project:

erlang 26.1.2
elixir 1.15.7
dialyxir 1.2 and 1.4

I'm not sure I can help with this but I'll take a look into it.

andrelip commented 6 months ago

+1 elixir 1.15.6-otp-26 erlang 26.1.1