3

I have a function with 2 default parameters

defp foo(bar, baz, qux \\ "", garply \\ nil)

I’ve got two usages, one supplies only the first two parameters, the other all 4. Dialyzer is complaining that Function foo/3 will never be called. I assume this is because it's private and the two defaults allow for unroll_nodes/2, unroll_nodes/3, and unroll_nodes/4. I could ostensibly drop the defaults and supply them in the current foo/2 invocation, but it seems silly just to placate dialyzer. Is there a way to specify this in the spec?

kolosy
  • 2,859
  • 3
  • 25
  • 47

1 Answers1

2

You can suppress the dialyzer warning using the @dialyzer attribute:

@dialyzer {:no_unused, [foo: 3]}

All possible options are listed here.

michalmuskala
  • 10,160
  • 1
  • 31
  • 46
  • does that mean there's no better way to specify the typespec? it truly is an errant warning? or is this a codesmell? – kolosy Jul 13 '17 at 16:37
  • 1
    I guess that's a combination of Elixir always generating all the intermediate heads. An alternative could be to define the defaults "manually" with a separate function call. Then you'd have only the /2 and /4 versions without the /3 version. – michalmuskala Jul 13 '17 at 19:07