user483040
user483040

Reputation:

Dialyzer hates my behaviour @callback definition

I've recently started to really leverage Dialyzer in my Elixir work but I'm seeing a strange error that I'm not sure how to correct. I've got a behaviour defined as:

defmodule NeatCo.Engine.ConnectionBehaviour do

  @callback connect(binary, integer, keyword) :: term
  ...

end

I use the behaviour in another module as:

defmodule NeatCo.Engine.Connection do

  @behaviour NeatCo.Engine.ConnectionBehaviour

  def connect(host, port, opts) do
    ...
  end

end

Dialyzer (running in VS Code) yells at that with:

"The inferred type for the 1st argument is not a supertype of the expected type for the connect/3 callback in the NeatCo.Engine.Connection behaviour"

My (possibly mistaken) understanding is that String.t is an alias for binary, suggesting that they are the same thing and as such I'd expect this to be acceptable--I'm passing in a string.

I've tried a few things that haven't worked--changed it to String.t, binary() for example. I'm pretty sure I'm off in the weeds, picking flowers.

For the sake of clarity: I'm running elixir 1.8.2, and using the 0.7.0 version of the ElixirLS extension in VS Code. Because 1.8.2 isn't supported in recent versions of that extension, I had to downgrade it to the last version that supported 1.8.

Upvotes: 0

Views: 213

Answers (0)

Related Questions