dialyxir icon indicating copy to clipboard operation
dialyxir copied to clipboard

Unknown error occurred: %Protocol.UndefinedError{description: "", protocol: String.Chars, value: {47, 1}}

Open rlipscombe opened this issue 3 years ago • 1 comments

Precheck

  • Take a look at the open issues and be sure that your issue is not already covered. -- I found a couple of vaguely-related issues, but none on point.
  • Be sure your versions of Dialyxir and Erlex are up to date. -- Yes.

Environment

  • Elixir & Erlang/OTP versions (elixir --version): 1.12.3 / OTP-24.0.6

  • Which version of Dialyxir are you using? (cat mix.lock | grep dialyxir): 1.0.0 (also fails with 1.1.0)

Current behavior

Running mix dialyze on a combined Erlang and Elixir project, I get the following error on my Erlang modules:

Unknown error occurred: %Protocol.UndefinedError{description: "", protocol: String.Chars, value: {47, 1}}

I strongly suspect that it's due to the fact that the "line number" in Erlang BEAM files now contains the column number (cf https://github.com/erlang-lager/lager/issues/558), and this is tripping dialyxir up.

If I use --format raw, I don't get the error. If I use --format short, I see lib/dialyxir/formatter.ex:73: Dialyxir.Formatter.format_warning/2 in the stack trace.

rlipscombe avatar Oct 11 '21 17:10 rlipscombe

The following patch against 1.1.0 fixes it:

diff --git a/lib/dialyxir/formatter.ex b/lib/dialyxir/formatter.ex
index 6aa9c38..4034f29 100644
--- a/lib/dialyxir/formatter.ex
+++ b/lib/dialyxir/formatter.ex
@@ -70,7 +70,7 @@ defmodule Dialyxir.Formatter do
     warning = warning(warning_name)
     string = warning.format_short(arguments)
 
-    "#{base_name}:#{line}:#{warning_name} #{string}"
+    "#{base_name}:#{format_line(line)}:#{warning_name} #{string}"
   end
 
   defp format_warning(dialyzer_warning = {_tag, {file, line}, message}, :dialyxir) do
@@ -83,7 +83,7 @@ defmodule Dialyxir.Formatter do
         string = warning.format_long(arguments)
 
         """
-        #{base_name}:#{line}:#{warning_name}
+        #{base_name}:#{format_line(line)}:#{warning_name}
         #{string}
         """
       rescue
@@ -138,6 +138,9 @@ defmodule Dialyxir.Formatter do
     formatted <> String.duplicate("_", 80)
   end
 
+  defp format_line({line, col}), do: "#{line}:#{col}"
+  defp format_line(line), do: "#{line}"
+
   defp wrap_error_message(message, warning) do
     """
     Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

rlipscombe avatar Oct 11 '21 17:10 rlipscombe