I have a function where I do:
def recomputeCapacity(%MapSet{} = mCallIds) do
cu =
mCallIds
|> MapSet.to_list()
And Dyalizer says that the function can never complete (and all the functions calling it…) because:
The call 'Elixir.MapSet':to_list
(_mCallIds@1 :: #{'__struct__' := 'Elixir.MapSet', _ => _}) does not have an opaque term of type
'Elixir.MapSet':t(_) as 1st argumentElixirLS Dialyzer
Now, if mCallIds
was an integer or something I’d use a guard is_integer()
, but how do I make sure that only a MapSet can match this function?
I could have a
@spec recomputeCapacity( MapSet.t(any) ) :: number
But it would not prevent me calling the function by mistake, and if I leave the %MapSet{} = mCallIds
Dialyzer keeps complaining.
I know that MapSet is opaque so I should not pattern-match on it (though - annoyingly - it works…) but what is the alternative?