Code
Let’s say I have a function that returns a map. This function can have 0 and 1 arity:
@spec new_game(String.t) :: map
def new_game(a_word), do:
%{word: a_word}
@spec new_game :: map
def new_game, do:
new_game(Dictionary.random_word())
Now I am trying to spec this function. However, IIRC, since I have 2 different specs, dialyzer will override the first spec with the last one (could someone correct me here? I am fairly sure this happens in some occasions).
Questions
- Is it possible to have only one
spec
definition that covers both cases of this function? - Are there any drawbacks in have multiple specs per function?