Reputation: 237
Dialyzer complains about Phoenix models when they are set up in the usual way, i.e.
def changeset(model, params \\ :empty)
...
the params instruct how the model is to be updated, with :empty as a default to differentiate between a blank form submission with 'params' equal to an empty map.
Dialyzer warns:
The call 'Elixir.Backend.Plot':
changeset(x0@1::any(),'empty') will never return since it differs in the 2nd argument from the success typing arguments:
(#{},#{})
if I remove the ':empty' default param the warning disappears.
Is there a spec which satisfies the type checker while keeping the usual default changeset function? Any hints or pointers?
Upvotes: 1
Views: 404
Reputation: 15293
It's hard to advise you about exactly what you should do to deal with this since I don't know the exact type spec you're providing. However, I think if you mark that second parameter as potentially being an empty map it should work as you want.
Look here. It seems as if maps aren't specifically supported by dialyzer but there seems to be a relatively simple workaround. Make the specification #{ any() => any() }
However, as is mentioned in that message it's not totally clear if that will work with empty maps or not.
EDIT:
It appears that I was a little bit unclear in my response. When I say "spec" I mean that annotation that you add above the function to tell dialyzer how you expect your function to behave. For example:
@spec get_short_name(Path.t)::Path.t
def get_short_name(path) when is_binary(path) do
If you haven't specified any @spec at all then that may be your issue.
In the case you specified above, I'd suggest that something like this may work:
@spec changeset(#{any() => any()}, #{any() => any()})::returntype
def changeset(model, params \\ :empty)
You'd want to modify returntype to be whatever type changeset returns and I can't tell from the fragment you posted what the type of model should be so I guessed it's a map. As I say, since I don't know the details of what you're doing with changeset and since you don't seem to have specified a @spec, it's sort of tough for me to say.
Upvotes: 1