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

Error on Dialyxir.Warnings.InvalidContract.format_long #501

Open
nikitalocalhost opened this issue May 24, 2023 · 3 comments
Open

Error on Dialyxir.Warnings.InvalidContract.format_long #501

nikitalocalhost opened this issue May 24, 2023 · 3 comments

Comments

@nikitalocalhost
Copy link

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
Copy link

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

@crova
Copy link

crova commented Oct 18, 2023

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
Copy link

+1
elixir 1.15.6-otp-26
erlang 26.1.1

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

No branches or pull requests

4 participants