Skip to content

Double Specs not taken into account #36

@Fl4m3Ph03n1x

Description

@Fl4m3Ph03n1x

Background

I have a module of pure functions where I am adding specs. In one of my specs I have the wrong function name:

defmodule ImmutableValues do

  @spec first_two([String.t()]) :: [String.t()]
  def first_two([first, second | _tail]), do: [first, second]

  @spec first_two([String.t()]) :: [String.t()]
  def last_two(list) do
    [last, penultimate | _tail] = Enum.reverse(list)
    [penultimate, last]
  end

end

This means two things:

  • I have no spec for last_two
  • first_two has a double spec

Actual behaviour

mix gradient
Compiling 1 file (.ex)
Typechecking files...
No problems found!

Expected behaviour

Now, obviously I made this mistake by copy pasting specs. However, I expected one of the two possible errors:

  • A message complaining that last_two has a missing spec
  • A message complaining that first_two has a double spec

What would be really awesome would be the tool detecting that the spec I intended for last_two is likely incorrectly named (perhaps this would be possible by checking the line number of the spec and the line number of the function declaration).

Dialyzer goes for option 2, complaining about a duplicate spec.

Why am I reporting this?

It is my personal opinion that the current implementation that detects no errors is incorrect. At least from a user's point of view, it makes little sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions